question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consuming projects are not updated when a CopyToOutputDirectory item is updated in a project with no project references.

See original GitHub issue

Visual 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:

  1. 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 and TextFileB.txt are copied to the output directory with PreserveNewest 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.
  2. Open the solution in Visual Studio.
  3. Select TestProgram as the startup project.
  4. 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.
    
  5. 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.
    
  6. 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.
    
  7. Observe that the file is updated in LibraryB’s output (LibraryB\bin\Debug\netstandard2.0\TextFileB.txt), but not in TestProgram’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:

  1. Add a dummy reference to the library.
  2. Create the copy marker yourself using MSBuild.

Both are described in further detail in my demonstration repository.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
drewnoakescommented, Nov 28, 2022

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.

0reactions
davkeancommented, Mar 29, 2022

@drewnoakes We cheated for transitive project references and put them in the assets file. I would consider a similar approach for this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to copy output of referenced project in Visual Studio
Unfortunately no files are copied to Exe 's output dir. How can I teach VS/MSBuild to copy my files just like it copies...
Read more >
Common MSBuild Project Items
Learn about common MSBuild project items. Items are named references to one or more files, and have metadata like file names, paths, ...
Read more >
Visual Studio 2019 Always Rebuilds Up-To-Date Projects
Project 'Dodd.WPF' is not up to date. Project item 'xxxxxx\ReadOnlyApplicationConfiguration.xml' has 'Copy to Output Directory' attribute set to 'Copy always'.
Read more >
NuGet ContentFiles – Chris Andritzky's Blog
Here is the trick: To make content files flow seamlessly across transitive dependencies, the intermediate referencing project must set PrivateAssets=”analyzers; ...
Read more >
NuGetizer 0.8.0
NuGetizer makes it trivial to consume your locally-built packages from a sample test project to exercise its features, by automatically ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found