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

Opt-in .sln parsing with Microsoft.VisualStudio.SolutionPersistence #11538

Merged
merged 16 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eng/BootStrapMsBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<_NuGetRuntimeDependencies Include="%(RuntimeCopyLocalItems.Identity)" Condition="'@(RuntimeCopyLocalItems->Contains('Newtonsoft.Json'))' == 'true'" />
<_NuGetRuntimeDependencies Include="%(RuntimeCopyLocalItems.Identity)" Condition="'@(RuntimeCopyLocalItems->Contains('NuGetSdkResolver'))' == 'true'" />
<_NuGetRuntimeDependencies Include="%(RuntimeCopyLocalItems.Identity)" Condition="'@(RuntimeCopyLocalItems->Contains('Microsoft.Extensions.'))' == 'true'" />

<_NuGetRuntimeDependencies Include="%(RuntimeCopyLocalItems.Identity)" Condition="'@(RuntimeCopyLocalItems->Contains('Microsoft.VisualStudio.SolutionPersistence'))' == 'true'" />

<!-- NuGet.targets and NuGet.RestoreEx.targets will be in the RuntimeTargetsCopyLocalItems ItemGroup -->
<_NuGetRuntimeDependencies Include="%(RuntimeTargetsCopyLocalItems.Identity)" Condition="'@(RuntimeTargetsCopyLocalItems->Contains('NuGet.'))' == 'true'" />

Expand All @@ -48,7 +49,7 @@

<Target Name="RemoveExtraAssemblyReferences" BeforeTargets="ResolveAssemblyReferences">
<!-- This is really hacky, but these references will cause issues when trying to 'build' this project.
To acquire the NuGet binaries we depend on for local run-time ('bootstrap'), we we are using a PackageReference (to
To acquire the NuGet binaries we depend on for local run-time ('bootstrap'), we are using a PackageReference (to
'NuGet.Build.Tasks' and 'Microsoft.Build.NuGetSdkResolver'). This has the advantage of using NuGets compatibility
check to ensure we choose the right version of those assemblies. But, at 'bootstrap' time these runtime dependencies
need to be in a specific location that does not mesh with NuGet. To resolve this, we include the default
Expand Down
738 changes: 101 additions & 637 deletions src/Build.OM.UnitTests/Construction/SolutionFile_Tests.cs

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions src/Build.UnitTests/Construction/SolutionFile_NewParser_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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.
/// </summary>
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)
Expand Down
Loading
Loading