diff --git a/eng/Versions.props b/eng/Versions.props index 2cc543b8d81..55da934adb3 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 17.13.14 + 17.13.15 release 17.12.6 15.1.0.0 diff --git a/src/Build.OM.UnitTests/Construction/SolutionFile_Tests.cs b/src/Build.OM.UnitTests/Construction/SolutionFile_Tests.cs index fcf15461cc3..a09ee594d91 100644 --- a/src/Build.OM.UnitTests/Construction/SolutionFile_Tests.cs +++ b/src/Build.OM.UnitTests/Construction/SolutionFile_Tests.cs @@ -24,8 +24,21 @@ namespace Microsoft.Build.UnitTests.Construction /// /// Tests for the parts of SolutionFile that are surfaced as public API /// - public class SolutionFile_Tests + public class SolutionFile_Tests : IDisposable { + + private readonly TestEnvironment _testEnvironment; + + public SolutionFile_Tests() + { + _testEnvironment = TestEnvironment.Create(); + } + + public void Dispose() + { + _testEnvironment.Dispose(); + } + /// /// Test that a project with the C++ project guid and an extension of vcproj is seen as invalid. /// @@ -57,7 +70,7 @@ public void ParseSolution_VC() Assert.Throws(() => { - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); Assert.Fail("Should not get here"); }); } @@ -93,7 +106,7 @@ public void ParseSolution_VC2(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); string expectedProjectName = convertToSlnx ? "Project name" : "Project name.myvctype"; Assert.Equal(expectedProjectName, solution.ProjectsInOrder[0].ProjectName); @@ -137,7 +150,7 @@ public void ParseSolution_EmptyProjectName() Assert.Throws(() => { - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); }); } @@ -184,7 +197,7 @@ public void BasicSolution(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); Assert.Equal(3, solution.ProjectsInOrder.Count); @@ -266,7 +279,7 @@ public void SolutionFolders(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); Assert.Equal(3, solution.ProjectsInOrder.Count); @@ -351,7 +364,7 @@ public void SolutionDependencies(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); Assert.Equal(3, solution.ProjectsInOrder.Count); @@ -432,7 +445,7 @@ public void ParseSolutionConfigurations(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); Assert.Equal(7, solution.SolutionConfigurations.Count); @@ -494,7 +507,7 @@ public void ParseSolutionConfigurationsNoMixedPlatform(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); Assert.Equal(6, solution.SolutionConfigurations.Count); @@ -569,7 +582,7 @@ public void ParseProjectConfigurationsInSolutionConfigurations1(bool convertToSl EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); ProjectInSolution csharpProject = solution.ProjectsInOrder.First(p => p.ProjectName == "ClassLibrary1"); ProjectInSolution vcProject = solution.ProjectsInOrder.First(p => p.ProjectName == "MainApp"); @@ -654,7 +667,7 @@ public void ParseProjectConfigurationsInSolutionConfigurations2(bool convertToSl EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents, convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents, convertToSlnx); ProjectInSolution winFormsApp1 = solution.ProjectsInOrder.First(p => p.ProjectName == "WinFormsApp1"); ProjectInSolution classLibrary1 = solution.ProjectsInOrder.First(p => p.ProjectName == "ClassLibrary1"); @@ -680,18 +693,13 @@ public void ParseProjectConfigurationsInSolutionConfigurations2(bool convertToSl /// Helper method to create a SolutionFile object, and call it to parse the SLN file /// represented by the string contents passed in. Optionally can convert the SLN to SLNX and then parse the solution. /// - private static SolutionFile ParseSolutionHelper(string solutionFileContents, bool convertToSlnx = false) + private static SolutionFile ParseSolutionHelper(TestEnvironment testEnvironment, string solutionFileContents, bool convertToSlnx = false) { solutionFileContents = solutionFileContents.Replace('\'', '"'); - - using (TestEnvironment testEnvironment = TestEnvironment.Create()) - { - TransientTestFile sln = testEnvironment.CreateFile(FileUtilities.GetTemporaryFileName(".sln"), solutionFileContents); - - string solutionPath = convertToSlnx ? ConvertToSlnx(sln.Path) : sln.Path; - - return SolutionFile.Parse(solutionPath); - } + testEnvironment.SetEnvironmentVariable("MSBUILD_SLN_PARSING_SOLUTIONPERSISTENCE_OPTIN", "1"); + TransientTestFile sln = testEnvironment.CreateFile(FileUtilities.GetTemporaryFileName(".sln"), solutionFileContents); + string solutionPath = convertToSlnx ? ConvertToSlnx(sln.Path) : sln.Path; + return SolutionFile.Parse(solutionPath); } private static string ConvertToSlnx(string slnPath) diff --git a/src/Build.UnitTests/Construction/SolutionFile_NewParser_Tests.cs b/src/Build.UnitTests/Construction/SolutionFile_NewParser_Tests.cs index 7f56b600dca..bf588b40394 100644 --- a/src/Build.UnitTests/Construction/SolutionFile_NewParser_Tests.cs +++ b/src/Build.UnitTests/Construction/SolutionFile_NewParser_Tests.cs @@ -20,13 +20,21 @@ namespace Microsoft.Build.UnitTests.Construction { - public class SolutionFile_NewParser_Tests + public class SolutionFile_NewParser_Tests : IDisposable { public ITestOutputHelper TestOutputHelper { get; } + private readonly TestEnvironment _testEnvironment; + public SolutionFile_NewParser_Tests(ITestOutputHelper testOutputHelper) { TestOutputHelper = testOutputHelper; + _testEnvironment = TestEnvironment.Create(); + } + + public void Dispose() + { + _testEnvironment.Dispose(); } /// @@ -80,7 +88,7 @@ public void ProjectWithWebsiteProperties(bool convertToSlnx) EndGlobal """; - SolutionFile solution = ParseSolutionHelper(solutionFileContents.Replace('`', '"'), convertToSlnx); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents.Replace('`', '"'), convertToSlnx); solution.ProjectsInOrder.ShouldHaveSingleItem(); @@ -129,20 +137,15 @@ public void ProjectWithWebsiteProperties(bool convertToSlnx) /// Helper method to create a SolutionFile object, and call it to parse the SLN file /// represented by the string contents passed in. Optionally can convert the SLN to SLNX and then parse the solution. /// - internal static SolutionFile ParseSolutionHelper(string solutionFileContents, bool convertToSlnx = false) + internal static SolutionFile ParseSolutionHelper(TestEnvironment testEnvironment, string solutionFileContents, bool convertToSlnx = false) { solutionFileContents = solutionFileContents.Replace('\'', '"'); - - using (TestEnvironment testEnvironment = TestEnvironment.Create()) - { - TransientTestFile sln = testEnvironment.CreateFile(FileUtilities.GetTemporaryFileName(".sln"), solutionFileContents); - - string solutionPath = convertToSlnx ? ConvertToSlnx(sln.Path) : sln.Path; - - SolutionFile solutionFile = new SolutionFile { FullPath = solutionPath }; - solutionFile.ParseUsingNewParser(); - return solutionFile; - } + testEnvironment.SetEnvironmentVariable("MSBUILD_SLN_PARSING_SOLUTIONPERSISTENCE_OPTIN", "1"); + TransientTestFile sln = testEnvironment.CreateFile(FileUtilities.GetTemporaryFileName(".sln"), solutionFileContents); + string solutionPath = convertToSlnx ? ConvertToSlnx(sln.Path) : sln.Path; + SolutionFile solutionFile = new SolutionFile { FullPath = solutionPath }; + solutionFile.ParseUsingNewParser(); + return solutionFile; } private static string ConvertToSlnx(string slnPath) diff --git a/src/Build.UnitTests/Construction/SolutionFile_OldParser_Tests.cs b/src/Build.UnitTests/Construction/SolutionFile_OldParser_Tests.cs index ab51906b222..708cee21ab9 100644 --- a/src/Build.UnitTests/Construction/SolutionFile_OldParser_Tests.cs +++ b/src/Build.UnitTests/Construction/SolutionFile_OldParser_Tests.cs @@ -17,13 +17,21 @@ namespace Microsoft.Build.UnitTests.Construction { - public class SolutionFile_OldParser_Tests + public class SolutionFile_OldParser_Tests : IDisposable { public ITestOutputHelper TestOutputHelper { get; } + private readonly TestEnvironment _testEnvironment; + public SolutionFile_OldParser_Tests(ITestOutputHelper testOutputHelper) { TestOutputHelper = testOutputHelper; + _testEnvironment = TestEnvironment.Create(); + } + + public void Dispose() + { + _testEnvironment.Dispose(); } /// @@ -134,7 +142,7 @@ public void ParseSolutionWithDifferentSpacing() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); Assert.Equal("Project name", solution.ProjectsInOrder[0].ProjectName); Assert.Equal("Relative path to project file", solution.ProjectsInOrder[0].RelativePath); @@ -200,7 +208,7 @@ public void ParseEtpProject() ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject"; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); // Project should get added to the solution solution.ProjectsInOrder[0].RelativePath.ShouldBe(@"someproj.etp"); solution.ProjectsInOrder[1].RelativePath.ShouldBe(@"ClassLibrary2.csproj"); @@ -274,7 +282,7 @@ public void CanBeMSBuildFile() EndProject"; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution project = solution.ProjectsByGuid["{AD0F3D02-9925-4D57-9DAF-E0A9D936ABDB}"]; ProjectInSolution project2 = solution.ProjectsByGuid["{CCCCCCCC-9925-4D57-9DAF-E0A9D936ABDB}"]; project.CanBeMSBuildProjectFile(out _).ShouldBeFalse(); @@ -328,7 +336,7 @@ public void CanBeMSBuildFileRejectsMSBuildLikeFiles() EndProjectSection EndProject"; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution project1 = solution.ProjectsByGuid["{CCCCCCCC-9925-4D57-9DAF-E0A9D936ABDB}"]; ProjectInSolution project2 = solution.ProjectsByGuid["{DEA89696-F42B-4B58-B7EE-017FF40817D1}"]; @@ -389,7 +397,7 @@ public void ParseNestedEtpProjectSingleLevel() ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject"; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); // Project should get added to the solution solution.ProjectsInOrder[0].RelativePath.ShouldBe(@"someproj.etp"); @@ -416,7 +424,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionPriorToDev12 = ParseSolutionHelper(solutionFileContentsPriorToDev12); + SolutionFile solutionPriorToDev12 = ParseSolutionHelper(_testEnvironment, solutionFileContentsPriorToDev12); solutionPriorToDev12.Version.ShouldBe(11); solutionPriorToDev12.VisualStudioVersion.ShouldBe(10); @@ -432,7 +440,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12 = ParseSolutionHelper(solutionFileContentsDev12); + SolutionFile solutionDev12 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12); solutionDev12.Version.ShouldBe(11); solutionDev12.VisualStudioVersion.ShouldBe(12); @@ -450,7 +458,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12Corrupted1 = ParseSolutionHelper(solutionFileContentsDev12Corrupted1); + SolutionFile solutionDev12Corrupted1 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12Corrupted1); solutionDev12Corrupted1.Version.ShouldBe(11); solutionDev12Corrupted1.VisualStudioVersion.ShouldBe(10); @@ -465,7 +473,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12Corrupted2 = ParseSolutionHelper(solutionFileContentsDev12Corrupted2); + SolutionFile solutionDev12Corrupted2 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12Corrupted2); solutionDev12Corrupted2.Version.ShouldBe(11); solutionDev12Corrupted2.VisualStudioVersion.ShouldBe(10); @@ -480,7 +488,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12Corrupted3 = ParseSolutionHelper(solutionFileContentsDev12Corrupted3); + SolutionFile solutionDev12Corrupted3 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12Corrupted3); solutionDev12Corrupted3.Version.ShouldBe(11); solutionDev12Corrupted3.VisualStudioVersion.ShouldBe(10); @@ -495,7 +503,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12Corrupted4 = ParseSolutionHelper(solutionFileContentsDev12Corrupted4); + SolutionFile solutionDev12Corrupted4 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12Corrupted4); solutionDev12Corrupted4.Version.ShouldBe(11); solutionDev12Corrupted4.VisualStudioVersion.ShouldBe(10); @@ -510,7 +518,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12Corrupted5 = ParseSolutionHelper(solutionFileContentsDev12Corrupted5); + SolutionFile solutionDev12Corrupted5 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12Corrupted5); solutionDev12Corrupted5.Version.ShouldBe(11); solutionDev12Corrupted5.VisualStudioVersion.ShouldBe(10); @@ -525,7 +533,7 @@ public void TestVSAndSolutionVersionParsing() EndProjectSection EndProject"; - SolutionFile solutionDev12Corrupted6 = ParseSolutionHelper(solutionFileContentsDev12Corrupted6); + SolutionFile solutionDev12Corrupted6 = ParseSolutionHelper(_testEnvironment, solutionFileContentsDev12Corrupted6); solutionDev12Corrupted6.Version.ShouldBe(11); solutionDev12Corrupted6.VisualStudioVersion.ShouldBe(12); } @@ -604,7 +612,7 @@ public void ParseNestedEtpProjectMultipleLevel() ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject"; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); // Project should get added to the solution solution.ProjectsInOrder[0].RelativePath.ShouldBe(@"someproj.etp"); @@ -662,7 +670,7 @@ public void MalformedEtpProjFile() ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject"; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); string errCode; ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errCode, out _, "Shared.InvalidProjectFile", "someproj.etp", String.Empty); @@ -697,7 +705,7 @@ public void MissingEtpProjFile() EndProject"; // Delete the someproj.etp file if it exists File.Delete(proj1Path); - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); string errCode; ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out errCode, out _, "Shared.ProjectFileCouldNotBeLoaded", "someproj.etp", String.Empty); @@ -754,7 +762,7 @@ public void ParseSolutionWhereProjectNameHasSpecialCharacters() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); Assert.Equal("MyProject,(=IsGreat)", solution.ProjectsInOrder[0].ProjectName); Assert.Equal("Relative path to project file", solution.ProjectsInOrder[0].RelativePath); @@ -794,18 +802,13 @@ public void ParseFirstProjectLineWhereProjectPathHasBackslash() /// /// /// - internal static SolutionFile ParseSolutionHelper(string solutionFileContents) + internal static SolutionFile ParseSolutionHelper(TestEnvironment testEnvironment, string solutionFileContents) { solutionFileContents = solutionFileContents.Replace('\'', '"'); - StreamReader sr = StreamHelpers.StringToStreamReader(solutionFileContents); - - SolutionFile sp = new SolutionFile(); - sp.SolutionFileDirectory = Path.GetTempPath(); - sp.SolutionReader = sr; - sp.FullPath = FileUtilities.GetTemporaryFileName(".sln"); - sp.ParseSolution(); - // Clean up the temporary file that got created with this call - return sp; + TransientTestFile sln = testEnvironment.CreateFile(FileUtilities.GetTemporaryFileName(".sln"), solutionFileContents); + SolutionFile solutionFile = new SolutionFile { FullPath = sln.Path }; + solutionFile.ParseSolutionFile(); + return solutionFile; } /// @@ -823,7 +826,7 @@ public void BadVersionStamp() # Visual Studio 2005 "; - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); }); } /// @@ -840,7 +843,7 @@ public void VersionTooLow() # Visual Studio 2005 "; - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); }); } /// @@ -856,7 +859,7 @@ public void UnsupportedVersion() # Visual Studio 2005 "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.SolutionParserComments.ShouldHaveSingleItem(); // "Expected the solution parser to contain one comment" solution.SolutionParserComments[0].ShouldBe(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("UnrecognizedSolutionComment", "999")); } @@ -870,7 +873,7 @@ public void Version9() # Visual Studio 2005 "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.Version.ShouldBe(9); } @@ -884,7 +887,7 @@ public void Version10() # Visual Studio 2005 "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.Version.ShouldBe(10); } @@ -921,7 +924,7 @@ public void ParseSolutionFileWithDescriptionInformation() "; try { - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); } catch (Exception ex) { @@ -976,7 +979,7 @@ public void BasicSolution() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.ProjectsInOrder.Count.ShouldBe(4); @@ -1064,7 +1067,7 @@ public void SolutionFolders() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.ProjectsInOrder.Count.ShouldBe(5); @@ -1162,7 +1165,7 @@ public void ParseSolutionConfigurationWithEmptyLines() EndGlobal "; - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); } /// @@ -1211,7 +1214,7 @@ public void MissingNestedProject() InvalidProjectFileException e = Should.Throw(() => { - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); }); e.ErrorCode.ShouldBe("MSB5023"); @@ -1255,7 +1258,7 @@ public void IncorrectlyNestedProjectErrorContainsProjectNameAndGuid() EndGlobal "; - InvalidProjectFileException e = Should.Throw(() => ParseSolutionHelper(solutionFileContents)); + InvalidProjectFileException e = Should.Throw(() => ParseSolutionHelper(_testEnvironment, solutionFileContents)); e.ErrorCode.ShouldBe("MSB5009"); e.Message.ShouldContain("{1484A47E-F4C5-4700-B13F-A2BDB6ADD35E}"); @@ -1381,7 +1384,7 @@ public void BuildableProjects() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.ProjectsInOrder.Count.ShouldBe(6); @@ -1461,7 +1464,7 @@ public void SolutionDependencies() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.ProjectsInOrder.Count.ShouldBe(3); @@ -1536,7 +1539,7 @@ public void VenusProject() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents.Replace('`', '"')); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents.Replace('`', '"')); solution.ProjectsInOrder.ShouldHaveSingleItem(); @@ -1619,7 +1622,7 @@ public void VenusProjectInASolutionFolder() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.ProjectsInOrder.Count.ShouldBe(3); @@ -1688,7 +1691,7 @@ public void ParseSolutionConfigurations() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.SolutionConfigurations.Count.ShouldBe(7); @@ -1748,7 +1751,7 @@ public void ParseSolutionConfigurationsNoMixedPlatform() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); solution.SolutionConfigurations.Count.ShouldBe(6); @@ -1792,7 +1795,7 @@ public void ParseInvalidSolutionConfigurations1() EndGlobal "; - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); }); } /// @@ -1818,7 +1821,7 @@ public void ParseInvalidSolutionConfigurations2() EndGlobal "; - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); }); } /// @@ -1844,7 +1847,7 @@ public void ParseInvalidSolutionConfigurations3() EndGlobal "; - ParseSolutionHelper(solutionFileContents); + ParseSolutionHelper(_testEnvironment, solutionFileContents); }); } @@ -1887,7 +1890,7 @@ public void ParseAllProjectsContainedInInvalidSolutionEvenWhenMissingEndProject( EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); // What is needed to be checked is whether there were still both projects found in the invalid solution file ProjectInSolution classLibraryProject = solution.ProjectsByGuid["{6185CC21-BE89-448A-B3C0-D1C27112E595}"]; @@ -1954,7 +1957,7 @@ public void ParseProjectConfigurationsInSolutionConfigurations1() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution csProject = solution.ProjectsByGuid["{6185CC21-BE89-448A-B3C0-D1C27112E595}"]; ProjectInSolution vcProject = solution.ProjectsByGuid["{A6F99D27-47B9-4EA4-BFC9-25157CBDC281}"]; @@ -2039,7 +2042,7 @@ public void ParseProjectConfigurationsInSolutionConfigurations2() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution webProject = solution.ProjectsByGuid["{E8E75132-67E4-4D6F-9CAE-8DA4C883F418}"]; ProjectInSolution exeProject = solution.ProjectsByGuid["{25FD9E7C-F37E-48E0-9A7C-607FE4AACCC0}"]; @@ -2094,7 +2097,7 @@ public void ParseSolutionFileContainingProjectsWithParentSlnFolder() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution project1 = solution.ProjectsByGuid["{FC2889D9-6050-4D2E-B022-979CCFEEAAAC}"]; ProjectInSolution project2 = solution.ProjectsByGuid["{ED30D4A3-1214-410B-82BB-B61E5A9D05CA}"]; @@ -2163,7 +2166,7 @@ public void ParseSolutionFileContainingProjectsWithParentSlnFolder() ")] public void ParseSolutionFileContainingProjectsWithSimilarNames_TwoProjects(string solutionFileContents) { - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution project1 = solution.ProjectsByGuid["{FC2889D9-6050-4D2E-B022-979CCFEEAAAC}"]; ProjectInSolution project2 = solution.ProjectsByGuid["{ED30D4A3-1214-410B-82BB-B61E5A9D05CA}"]; @@ -2240,7 +2243,7 @@ public void ParseSolutionFileContainingProjectsWithSimilarNames_TwoProjects(stri ")] public void ParseSolutionFileContainingProjectsWithSimilarNames_ThreeProjects(string solutionFileContents) { - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInSolution project1 = solution.ProjectsByGuid["{6185CC21-BE89-448A-B3C0-D1C27112E595}"]; ProjectInSolution project2 = solution.ProjectsByGuid["{FC2889D9-6050-4D2E-B022-979CCFEEAAAC}"]; @@ -2295,7 +2298,7 @@ public void ParseSolutionFileContainingProjectsWithSimilarNames_ThreeProjects_On EndGlobal "; - Action parseSolution = () => ParseSolutionHelper(solutionFileContents); + Action parseSolution = () => ParseSolutionHelper(_testEnvironment, solutionFileContents); var exception = Should.Throw(parseSolution); string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out _, out _, "SolutionParseDuplicateProject", "Project.Named.With.Dots"); @@ -2339,7 +2342,7 @@ public void ParseSolutionFileContainingProjectsWithSimilarNames_ThreeProjects_On EndGlobal "; - Action parseSolution = () => ParseSolutionHelper(solutionFileContents); + Action parseSolution = () => ParseSolutionHelper(_testEnvironment, solutionFileContents); var exception = Should.Throw(parseSolution); string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out _, out _, "SolutionParseDuplicateProject", "Project_Named_With_Dots"); @@ -2385,7 +2388,7 @@ public void ParseSolutionFileContainingProjectsWithSimilarNames_FourProjects_One EndGlobal "; - Action parseSolution = () => ParseSolutionHelper(solutionFileContents); + Action parseSolution = () => ParseSolutionHelper(_testEnvironment, solutionFileContents); var exception = Should.Throw(parseSolution); string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword(out _, out _, "SolutionParseDuplicateProject", "Project_Named_With_Dots"); @@ -2422,7 +2425,7 @@ public void ParseSolutionWithParentedPaths() EndGlobal "; - SolutionFile solution = ParseSolutionHelper(solutionFileContents); + SolutionFile solution = ParseSolutionHelper(_testEnvironment, solutionFileContents); string expectedRelativePath = Path.Combine("..", "ProjectA", "ProjectA.csproj"); solution.ProjectsInOrder[0].ProjectName.ShouldBe("ProjectA"); solution.ProjectsInOrder[0].RelativePath.ShouldBe(expectedRelativePath); @@ -2480,7 +2483,7 @@ public void ParseSolutionWithComments() } stringBuilder.AppendLine(comment); - Should.NotThrow(() => ParseSolutionHelper(stringBuilder.ToString())); + Should.NotThrow(() => ParseSolutionHelper(_testEnvironment, stringBuilder.ToString())); } } } diff --git a/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs b/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs index cd359a54c8b..d0c001ec8ee 100644 --- a/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs +++ b/src/Build.UnitTests/Construction/SolutionProjectGenerator_Tests.cs @@ -34,6 +34,8 @@ public class SolutionProjectGenerator_Tests : IDisposable { private readonly ITestOutputHelper output; + private readonly TestEnvironment _testEnvironment; + private string _originalVisualStudioVersion = null; private static readonly BuildEventContext _buildEventContext = new BuildEventContext(0, 0, BuildEventContext.InvalidProjectContextId, 0); @@ -44,6 +46,8 @@ public SolutionProjectGenerator_Tests(ITestOutputHelper output) { this.output = output; + _testEnvironment = TestEnvironment.Create(); + // Save off the value for use during cleanup _originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion"); } @@ -53,6 +57,7 @@ public void Dispose() // Need to make sure the environment is cleared up for later tests Environment.SetEnvironmentVariable("VisualStudioVersion", _originalVisualStudioVersion); ProjectCollection.GlobalProjectCollection.UnloadAllProjects(); + _testEnvironment.Dispose(); } /// @@ -433,7 +438,7 @@ public void DefaultSubToolsetIfSolutionVersionSubToolsetDoesntExist() EndGlobal """; - SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(solutionFileContents); + SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInstance[] instances = SolutionProjectGenerator.Generate(solution, null, null, _buildEventContext, CreateMockLoggingService()); @@ -775,7 +780,7 @@ public void SolutionWithMissingDependencies() EndGlobal """; - SolutionFile sp = SolutionFile_OldParser_Tests.ParseSolutionHelper(solutionFileContents); + SolutionFile sp = SolutionFile_OldParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInstance[] instances = SolutionProjectGenerator.Generate(sp, null, null, _buildEventContext, CreateMockLoggingService()); }); } @@ -1596,7 +1601,7 @@ public void TestConfigurationPlatformDefaults1() EndGlobal """; - SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(solutionFileContents); + SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents); // These used to exist on the engine, but now need to be passed in explicitly IDictionary globalProperties = new Dictionary(); @@ -1634,7 +1639,7 @@ public void TestConfigurationPlatformDefaults2() EndGlobal """; - SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(solutionFileContents); + SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents); ProjectInstance[] instances = SolutionProjectGenerator.Generate(solution, null, null, BuildEventContext.Invalid, CreateMockLoggingService()); @@ -1845,7 +1850,7 @@ public void TestPredictSolutionConfigurationName() EndGlobal """; - SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(solutionFileContents); + SolutionFile solution = SolutionFile_OldParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents); IDictionary globalProperties = new Dictionary(); @@ -2875,8 +2880,8 @@ private void AssertProjectItemNameCount(ProjectInstance msbuildProject, string i private SolutionFile ParseSolutionHelper(string solutionFileContents, bool useNewParser) { - return useNewParser ? SolutionFile_NewParser_Tests.ParseSolutionHelper(solutionFileContents) : - SolutionFile_OldParser_Tests.ParseSolutionHelper(solutionFileContents); + return useNewParser ? SolutionFile_NewParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents) : + SolutionFile_OldParser_Tests.ParseSolutionHelper(_testEnvironment, solutionFileContents); } #endregion // Helper Functions diff --git a/src/Build/Construction/Solution/SolutionFile.cs b/src/Build/Construction/Solution/SolutionFile.cs index 909feaf74a6..757724d192b 100644 --- a/src/Build/Construction/Solution/SolutionFile.cs +++ b/src/Build/Construction/Solution/SolutionFile.cs @@ -193,7 +193,7 @@ internal int VisualStudioVersion internal bool UseNewParser => ShouldUseNewParser(_solutionFile); - internal static bool ShouldUseNewParser(string solutionFile) => ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_14) || FileUtilities.IsSolutionXFilename(solutionFile); + internal static bool ShouldUseNewParser(string solutionFile) => Traits.Instance.SlnParsingWithSolutionPersistenceOptIn || FileUtilities.IsSolutionXFilename(solutionFile); /// /// All projects in this solution, in the order they appeared in the solution file diff --git a/src/Framework/Traits.cs b/src/Framework/Traits.cs index 9180690cd73..bfc3b182591 100644 --- a/src/Framework/Traits.cs +++ b/src/Framework/Traits.cs @@ -134,6 +134,8 @@ public Traits() public readonly bool InProcNodeDisabled = Environment.GetEnvironmentVariable("MSBUILDNOINPROCNODE") == "1"; + public readonly bool SlnParsingWithSolutionPersistenceOptIn = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBUILD_SLN_PARSING_SOLUTIONPERSISTENCE_OPTIN")); + public static void UpdateFromEnvironment() { // Re-create Traits instance to update values in Traits according to current environment.