-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
Steps to reproduce
Download and unzip the following:
repro.zip
Scenario 1
- Navigate to
c\ - Run
msbuild - Notice the contents of
c\binincludea.txt,b.txt,c.txt - Delete
c\bin - Run
msbuild /p:BuildProjectReferences=false - Notice the contents of
c\binincludeb.txt,c.txt.a.txtis missing!
Scenario 2
- Open
repro.sln - In VS, build the Solution
- Notice the contents of
c\binincludea.txt,b.txt,c.txt - Delete
c\bin - In VS, build just the C project
- Notice the contents of
c\binincludeb.txt,c.txt.a.txtis missing!
Root Cause
The root cause for this issue is because of the following:
- Target
GetCopyToOutputDirectoryItemsis called on@(_MSBuildProjectReferenceExistent) @(_MSBuildProjectReferenceExistent)is populated by the_SplitProjectReferencesByFileExistencetarget, which uses@(ProjectReferenceWithConfiguration)@(ProjectReferenceWithConfiguration)is populated by theAssignProjectConfigurationtarget. However, the_SplitProjectReferencesByFileExistencedoes not declare that it depends onAssignProjectConfiguration!!!- When building a project,
AssignProjectConfigurationhappens to execute before_SplitProjectReferencesByFileExistence, so all is good. - When
BuildProjectReferences=true, project references are recursively built soGetCopyToOutputDirectoryItemswill have already been called on the project reference and the results would be cached - When
BuildProjectReferences=false, project references are not recursively built so the recursive call toGetCopyToOutputDirectoryItemsends up calling_SplitProjectReferencesByFileExistence, which sees that@(ProjectReferenceWithConfiguration)is empty. Effectively this makesGetCopyToOutputDirectoryItemsonly go "1 level deep" whenBuildProjectReferences=false
Other notes:
- VS adds
BuildProjectReferences=false, but because it uses the target result cache within the same build session,GetCopyToOutputDirectoryItemsis cached from the dependencies and works correctly. However when building a specific project, the dependencies might not be built and thus would not be populated. - A possible fix is just to have
_SplitProjectReferencesByFileExistencedepend onAssignProjectConfiguration
Environment data
MSBuild version: 16
OS info: Win10