Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution Rebuild might fail when a shared output directory is used #19534

Closed
MichaeIDietrich opened this issue Aug 5, 2021 · 8 comments
Closed
Assignees
Labels
Area-External untriaged Request triage from a team member

Comments

@MichaeIDietrich
Copy link

MichaeIDietrich commented Aug 5, 2021

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?

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-External untriaged Request triage from a team member labels Aug 5, 2021
@MichaeIDietrich
Copy link
Author

Related issue: #17645

@marcpopMSFT marcpopMSFT self-assigned this Aug 9, 2021
@marcpopMSFT
Copy link
Member

#17645 tracks the issues related to building to a common output folder. This is not recommended though as it's safer to compile and then copy after. We do not have plans at the moment to improve this experience beyond the UseCommonOutputDirectory flag already mentioned which has its drawbacks.

@tdykstra to investigate whether we should have a document covering UseCommonOutputDirectory and common output directory issues as the comment here covers the details: #17645 (comment)

@tdykstra
Copy link
Contributor

@ghogen
Copy link

ghogen commented Aug 11, 2021

@tdykstra Yes, thanks. Created issue as linked above.

@MichaeIDietrich
Copy link
Author

I just would like to add some info why a shared output directory is useful and might be kind of needed for some solutions.

On the one hand project-scoped output directories do not really scale well with large solutions because each executable project will copy all of its (transitive) NuGet DLLs into its output directory, same goes for test projects. (For our solution this ended up in several GB of duplicated DLLs in those directories which is especially problematic for the potentially limited space on build agents.)

And on the other hand it is far more closer to how it usually would end up on the customer's PCs where all binaries will be installed into one directory, e.g. like MS Office. (At least I would have no good idea how to finally copy all resulting files of all top level, executable projects into a final common directory while maintaining the default output locations for each project.)

Any recommendations would be pretty welcome, if there are any.
And thank you for taking the time to look at this.

@KalleOlaviNiemitalo
Copy link
Contributor

@MichaeIDietrich, Microsoft.Build.Artifacts looks like it could be used to "finally copy all resulting files". That would consume even more disk space, though.

@SebFerraro
Copy link

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

@Gav-Brown
Copy link

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.

MiYanni pushed a commit that referenced this issue Apr 25, 2024
[main] Update dependencies from dotnet/sdk
- Coherency Updates:
  - Microsoft.WindowsDesktop.App.Ref: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.WindowsDesktop.SharedFramework.x64.9.0: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.WindowsDesktop.TargetingPack.x64.9.0: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.NetCore.SharedFramework.x64.9.0: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Ref: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.NetCore.TargetingPack.x64.9.0: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Host.win-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.Platforms: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.runtime.linux-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.AspNetCore.App.Ref: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.AspNetCore.App.Ref.Internal: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.AspNetCore.App.Runtime.win-x64: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.AspNetCore.SharedFramework.x64.9.0: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - dotnet-dev-certs: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - dotnet-user-jwts: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - dotnet-user-secrets: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.aspnetcore: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.WindowsDesktop.App.Runtime.win-x64: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.WindowsDesktop.App.Runtime.win-x64: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.DotNet.Wpf.ProjectTemplates: from 9.0.0-preview.4.24218.2 to 9.0.0-preview.4.24219.1 (parent: Microsoft.WindowsDesktop.App.Runtime.win-x64)
  - Microsoft.FSharp.Compiler: from 12.8.400-beta.24218.1 to 12.8.400-beta.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.fsharp: from 8.0.400-beta.24218.1 to 8.0.400-beta.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.NET.ILLink.Tasks: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.Net.Compilers.Toolset: from 4.11.0-1.24218.2 to 4.11.0-1.24222.7 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.roslyn: from 4.11.0-1.24218.2 to 4.11.0-1.24222.7 (parent: Microsoft.NET.Sdk)
  - Microsoft.Build: from 17.11.0-preview-24218-01 to 17.11.0-preview-24222-11 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.msbuild: from 17.11.0-preview-24218-01 to 17.11.0-preview-24222-11 (parent: Microsoft.NET.Sdk)
  - NuGet.Build.Tasks: from 6.11.0-preview.1.27 to 6.11.0-preview.1.28 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Runtime.win-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Runtime.win-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)

 - Install node 20.x on windows build to fix aspnetcore build

 - Merge branch 'main' into darc-main-35a979bc-455b-4e15-b1bf-6da27d06b3a5

 - Rebootstrap VMR with arcade changes

 - Merge branch 'main' into darc-main-35a979bc-455b-4e15-b1bf-6da27d06b3a5

 - Remove patches
ViktorHofer pushed a commit that referenced this issue May 7, 2024
[main] Update dependencies from dotnet/sdk
- Coherency Updates:
  - Microsoft.WindowsDesktop.App.Ref: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.WindowsDesktop.SharedFramework.x64.9.0: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.WindowsDesktop.TargetingPack.x64.9.0: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.NetCore.SharedFramework.x64.9.0: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Ref: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.NetCore.TargetingPack.x64.9.0: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Host.win-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.Platforms: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.runtime.linux-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.AspNetCore.App.Ref: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.AspNetCore.App.Ref.Internal: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.AspNetCore.App.Runtime.win-x64: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - VS.Redist.Common.AspNetCore.SharedFramework.x64.9.0: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - dotnet-dev-certs: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - dotnet-user-jwts: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - dotnet-user-secrets: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.aspnetcore: from 9.0.0-preview.4.24218.1 to 9.0.0-preview.4.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.WindowsDesktop.App.Runtime.win-x64: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.WindowsDesktop.App.Runtime.win-x64: from 9.0.0-preview.4.24218.3 to 9.0.0-preview.4.24220.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.DotNet.Wpf.ProjectTemplates: from 9.0.0-preview.4.24218.2 to 9.0.0-preview.4.24219.1 (parent: Microsoft.WindowsDesktop.App.Runtime.win-x64)
  - Microsoft.FSharp.Compiler: from 12.8.400-beta.24218.1 to 12.8.400-beta.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.fsharp: from 8.0.400-beta.24218.1 to 8.0.400-beta.24223.1 (parent: Microsoft.NET.Sdk)
  - Microsoft.NET.ILLink.Tasks: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.Net.Compilers.Toolset: from 4.11.0-1.24218.2 to 4.11.0-1.24222.7 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.roslyn: from 4.11.0-1.24218.2 to 4.11.0-1.24222.7 (parent: Microsoft.NET.Sdk)
  - Microsoft.Build: from 17.11.0-preview-24218-01 to 17.11.0-preview-24222-11 (parent: Microsoft.NET.Sdk)
  - Microsoft.SourceBuild.Intermediate.msbuild: from 17.11.0-preview-24218-01 to 17.11.0-preview-24222-11 (parent: Microsoft.NET.Sdk)
  - NuGet.Build.Tasks: from 6.11.0-preview.1.27 to 6.11.0-preview.1.28 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Runtime.win-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)
  - Microsoft.NETCore.App.Runtime.win-x64: from 9.0.0-preview.4.24218.7 to 9.0.0-preview.4.24222.8 (parent: Microsoft.NET.Sdk)

 - Install node 20.x on windows build to fix aspnetcore build

 - Merge branch 'main' into darc-main-35a979bc-455b-4e15-b1bf-6da27d06b3a5

 - Rebootstrap VMR with arcade changes

 - Merge branch 'main' into darc-main-35a979bc-455b-4e15-b1bf-6da27d06b3a5

 - Remove patches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-External untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

7 participants