Solution Rebuild might fail when a shared output directory is used
See original GitHub issueSteps to Reproduce
- Clone https://github.com/MichaeIDietrich/TestRebuildError
- dotnet build
- 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:
- Created 2 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
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
If it helps, I posted a possible solution here which allows you to not set
UseCommonOutputDirectory
but just theOutputDir
and then projects, dlls, and NuGet dlls all get copied to a single “bin” folder without missingdeps.json
files etc.