Consuming projects are not updated when a CopyToOutputDirectory item is updated in a project with no project references.
See original GitHub issueVisual Studio Version: 2017 - 15.9.10
Also reproduced in 2019 RC.4 - 16.0.0
Summary:
Fast up-to-date checks will consider a project to be up-to-date even when a project it references is not up to date due to a stale CopyToOutputDirectory
item.
(I’ve found some workarounds which are described here.)
Steps to Reproduce:
- Clone this repository.
- The demonstration repository contains details on how the projects are set up. The most important thing to know is that
TextFileA.txt
andTextFileB.txt
are copied to the output directory withPreserveNewest
and the program prints their contents when it runs. - The repository also contains more details on my findings about the source of the issue.
- The steps from the repository for reproducing the problem are reproduced below for posterity.
- The demonstration repository contains details on how the projects are set up. The most important thing to know is that
- Open the solution in Visual Studio.
- Select
TestProgram
as the startup project. - Press F5 to start the program. The output is as follows:
Hello World! Hello from ClassA! Text file A reporting for duty! Hello from ClassB! Text file B reporting for duty! Done.
- Close the program and add a message
TextFileA.txt
and press F5 to start the program again. The output includes your message:Hello World! Hello from ClassA! Text file A reporting for duty! Hello, world! Hello from ClassB! Text file B reporting for duty! Done.
- Close the program and add a message to
TextFileB.txt
instead, press F5 to start the program again. The output will not include your message:Hello World! Hello from ClassA! Text file A reporting for duty! Hello, world! Hello from ClassB! Text file B reporting for duty! Done.
- Observe that the file is updated in
LibraryB
’s output (LibraryB\bin\Debug\netstandard2.0\TextFileB.txt
), but not inTestProgram
’s output (TestProgram\bin\Debug\netcoreapp2.2\TextFileB.txt
).
Expected Behavior:
TextFileB.txt
is updated in TestProgram
’s output folder when it is changed.
Actual Behavior:
TextFileB.txt
is not updated.
User Impact:
Ironically I actually found this bug while debugging a similar issue with a legacy-style C# project. Either way, the symptoms are the same even though it appears the cause is not.
This issue is very confusing because you can see that LibraryB
was built by Visual Studiom, but projects depending on it directly/indirectly were not. The copied file will be present in the output of LibraryB
, but not in TestProgram
. You can rebuild the solution or make dummy changes in TestProgram
to force things to update, but this is fairly annoying to remember to do. In our case, the copied file was a native library, so it was like changes to the native library weren’t working.
Workarounds:
Besides rebuilding, I’ve found two workarounds to this issue:
- Add a dummy reference to the library.
- Create the copy marker yourself using MSBuild.
Both are described in further detail in my demonstration repository.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:14 (13 by maintainers)
An update on this issue. I have another solution under test here that fixes the issue and doesn’t have the issues of the previous attempts. My only concern is that it may cause a lot more file system checks in large solutions with deep P2P reference graphs, which may regress performance. I’m doing more testing in this area.
@drewnoakes We cheated for transitive project references and put them in the assets file. I would consider a similar approach for this.