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.

Solution Rebuild might fail when a shared output directory is used

See original GitHub issue

Steps to Reproduce

  1. Clone https://github.com/MichaeIDietrich/TestRebuildError
  2. dotnet build
  3. dotnet msbuild -t:rebuild -m:1

msbuild command is used to disable parallel compilation, so the projects are built one after the other to easily reproduce this issue. On large solutions there is no need to limit parallel compilation.

Actual Behavior

Compilation fails:

TestRebuildError -> \TestRebuildError\bin\Debug\net5.0\TestRebuildError.dll
C:\Program Files\dotnet\sdk\5.0.301\Microsoft.Common.CurrentVersion.targets(4964,5): error MSB3030: Could not copy the file "\TestRebuildError\bin\Debug\net5.0\TestRebuildError.runtimeconfig.dev.json" because it was not found. [\TestRebuildError\TestRebuildError.Tests\TestRebuildError.Tests.csproj]
C:\Program Files\dotnet\sdk\5.0.301\Microsoft.Common.CurrentVersion.targets(4964,5): error MSB3030: Could not copy the file "\TestRebuildError\bin\Debug\net5.0\TestRebuildError.deps.json" because it was not found. [\TestRebuildError\TestRebuildError.Tests\TestRebuildError.Tests.csproj]
C:\Program Files\dotnet\sdk\5.0.301\Microsoft.Common.CurrentVersion.targets(4964,5): error MSB3030: Could not copy the file "\TestRebuildError\bin\Debug\net5.0\TestRebuildError.runtimeconfig.json" because it was not found. [\TestRebuildError\TestRebuildError.Tests\TestRebuildError.Tests.csproj]

Expected Behavior

Both projects compile successfully.

Analyzation

The Clean target of the test project will also clear the *.deps.json of the referenced project, which then leads to the issue that the test project can no longer copy the *.deps.json file when the CopyFilesToOutputDirectory target is invoked to copy transtively referenced items.

There is a FileWritesShareable item group that is used to filter out shared items so the Clean target does not delete shared files. But for some reason it does not work for *.runtimeconfig.dev.json, *.runtimeconfig.json and *.deps.json.

Workaround

Setting UseCommonOutputDirectory to true will prevent any copying and cleaning of transitively referenced items and might be the recommended solution here.

Edit: As it turns out the workaround does not work as expected, since it also prevents any referenced item to be copied. Unfortunately there is a condition on the Copy task within the _CopyFilesMarkedCopyLocal target.

Question

~While there is a workaround~, I still think that not using UseCommonOutputDirectory should compile nevertheless. There is no information UseCommonOutputDirectory. Maybe this property should be officially documented somewhere?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SebFerrarocommented, Jan 12, 2022

Regardless of whether UseCommonOutputDirectory is documented or not, I still believe it should be possible to easily build several projects to one output directory. This will most likely cause issues if people (like ourselves) are starting to migrate some older projects to SDK format - that is what seemingly broke our builds

0reactions
Gav-Browncommented, Aug 26, 2022

If it helps, I posted a possible solution here which allows you to not set UseCommonOutputDirectory but just the OutputDir and then projects, dlls, and NuGet dlls all get copied to a single “bin” folder without missing deps.json files etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Rebuild ALL Fail after moving solution folder to a ...
The most likely cause of this error is that the location you are moving the solution to is not trusted.
Read more >
Visual Studio Could not write to output file annoyance | Blog
In my case, I'm not using a shared output folder, I am using Copy Local, and the project with the issues is only...
Read more >
NETSDK1045: The current .NET SDK does not support ...
Open the Solution Properties window (ctrl-click the solution in the Solution window and select Properties), select Build - General, and uncheck ...
Read more >
Visual Studio 2019 Always Rebuilds Up-To-Date Projects
If it still not works, please go to Tools -> Options and choose Projects and Solutions -> Build and Run and select Diagnostic...
Read more >
Dotnet restore vs nuget restore. Share. In my code repo, there
I can build and run in Visual Studio 2017 RC, but fails at command line. AuthHelper. Ideally you would use a nuget. The...
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