From b00d82cd845851c4c3f8373178da5c79f5ff2810 Mon Sep 17 00:00:00 2001 From: Nathan Mytelka Date: Wed, 19 May 2021 13:30:33 -0700 Subject: [PATCH 1/3] Do not use Exclude Exclude takes a snapshot of what we're excluding. We change the Enumerable mid-enumeration, which makes that invalid. --- .../Solution/SolutionProjectGenerator.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Build/Construction/Solution/SolutionProjectGenerator.cs b/src/Build/Construction/Solution/SolutionProjectGenerator.cs index 3888a265e50..4b1edd904a4 100644 --- a/src/Build/Construction/Solution/SolutionProjectGenerator.cs +++ b/src/Build/Construction/Solution/SolutionProjectGenerator.cs @@ -781,8 +781,9 @@ private void EvaluateAndAddProjects(List projectsInOrder, Lis AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, "Rebuild", "BuildOutput", canBuildDirectly); AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, "Publish", null, canBuildDirectly); - // Add any other targets specified by the user that were not already added - foreach (string targetName in _targetNames.Except(traversalInstance.Targets.Keys, StringComparer.OrdinalIgnoreCase)) + // Add any other targets specified by the user that were not already added. A target's presence or absence must be determined at the last + // minute because whether traversalInstance.Targets.ContainsKey(i) is true or not can change during the enumeration. + foreach (string targetName in _targetNames.Where(i => !traversalInstance.Targets.ContainsKey(i))) { AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, targetName, null, canBuildDirectly); } @@ -796,7 +797,7 @@ private void EvaluateAndAddProjects(List projectsInOrder, Lis } // Add any other targets specified by the user that were not already added - foreach (string targetName in _targetNames.Except(traversalInstance.Targets.Keys, StringComparer.OrdinalIgnoreCase)) + foreach (string targetName in _targetNames.Where(i => !traversalInstance.Targets.ContainsKey(i))) { AddTraversalReferencesTarget(traversalInstance, targetName, null); } @@ -1201,7 +1202,7 @@ private ProjectInstance CreateMetaproject(ProjectInstance traversalProject, Proj AddMetaprojectTargetForWebProject(traversalProject, metaprojectInstance, project, "Rebuild"); AddMetaprojectTargetForWebProject(traversalProject, metaprojectInstance, project, "Publish"); - foreach (string targetName in _targetNames.Except(metaprojectInstance.Targets.Keys, StringComparer.OrdinalIgnoreCase)) + foreach (string targetName in _targetNames.Where(i => !metaprojectInstance.Targets.ContainsKey(i))) { AddMetaprojectTargetForWebProject(traversalProject, metaprojectInstance, project, targetName); } @@ -1221,7 +1222,7 @@ private ProjectInstance CreateMetaproject(ProjectInstance traversalProject, Proj AddMetaprojectTargetForManagedProject(traversalProject, metaprojectInstance, project, projectConfiguration, "Rebuild", targetOutputItemName); AddMetaprojectTargetForManagedProject(traversalProject, metaprojectInstance, project, projectConfiguration, "Publish", null); - foreach (string targetName in _targetNames.Except(metaprojectInstance.Targets.Keys, StringComparer.OrdinalIgnoreCase)) + foreach (string targetName in _targetNames.Where(i => !metaprojectInstance.Targets.ContainsKey(i))) { AddMetaprojectTargetForManagedProject(traversalProject, metaprojectInstance, project, projectConfiguration, targetName, null); } @@ -1233,7 +1234,7 @@ private ProjectInstance CreateMetaproject(ProjectInstance traversalProject, Proj AddMetaprojectTargetForUnknownProjectType(traversalProject, metaprojectInstance, project, "Rebuild", unknownProjectTypeErrorMessage); AddMetaprojectTargetForUnknownProjectType(traversalProject, metaprojectInstance, project, "Publish", unknownProjectTypeErrorMessage); - foreach (string targetName in _targetNames.Except(metaprojectInstance.Targets.Keys, StringComparer.OrdinalIgnoreCase)) + foreach (string targetName in _targetNames.Where(i => !metaprojectInstance.Targets.ContainsKey(i))) { AddMetaprojectTargetForUnknownProjectType(traversalProject, metaprojectInstance, project, targetName, unknownProjectTypeErrorMessage); } From 94ce625ce7df557c134a10da5bc0a2f137fce888 Mon Sep 17 00:00:00 2001 From: Nathan Mytelka Date: Wed, 19 May 2021 15:47:28 -0700 Subject: [PATCH 2/3] Add test --- .../SolutionProjectGenerator_Tests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs b/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs index 5d536380d86..b75fa9b28be 100644 --- a/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs +++ b/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs @@ -175,6 +175,46 @@ public void SolutionFilterFiltersProjects() } } + [Fact] + public void BuildProjectAsTarget() + { + using (TestEnvironment testEnvironment = TestEnvironment.Create()) + { + TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true); + TransientTestFolder classLibFolder = testEnvironment.CreateFolder(Path.Combine(folder.Path, "classlib"), createFolder: true); + TransientTestFile classLibrary = testEnvironment.CreateFile(classLibFolder, "classlib.csproj", + @" + + + + + "); + + TransientTestFolder simpleProjectFolder = testEnvironment.CreateFolder(Path.Combine(folder.Path, "simpleProject"), createFolder: true); + TransientTestFile simpleProject = testEnvironment.CreateFile(simpleProjectFolder, "simpleProject.csproj", + @" + + + + + "); + + TransientTestFile solutionFile = testEnvironment.CreateFile(folder, "testFolder.sln", + @" +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.6.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""simpleProject"", ""simpleProject\simpleProject.csproj"", ""{AA52A05F-A9C0-4C89-9933-BF976A304C91}"" +EndProject +Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""classlib"", ""classlib\classlib.csproj"", ""{80B8E6B8-E46D-4456-91B1-848FD35C4AB9}"" +EndProject + "); + RunnerUtilities.ExecMSBuild(solutionFile.Path + " /t:classlib", out bool success); + success.ShouldBeTrue(); + } + } + /// /// Verify the AddNewErrorWarningMessageElement method /// From d6a27ddb46d87723e62806b67cbc54b6c64e2912 Mon Sep 17 00:00:00 2001 From: Rainer Sigwald Date: Thu, 20 May 2021 13:44:03 -0500 Subject: [PATCH 3/3] Bump version to 16.10.1 --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 8e634804ad6..2f588dda9d6 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 16.10.0release + 16.10.1release 15.1.0.0 preview true