-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
.SLNX format support #10794
Open
surayya-MS
wants to merge
15
commits into
dotnet:main
Choose a base branch
from
surayya-MS:slnx-support-first
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
.SLNX format support #10794
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3d1897d
include SolutionPersistence package
surayya-MS 86f4847
add slnx in XMake.ProcessProjectSwitch
surayya-MS 8a60719
support for .slnx format
surayya-MS e734a1b
small fix
surayya-MS 32bc09f
update package
surayya-MS 9fd5e8c
fix comment
surayya-MS 221fb65
Apply suggestions from code review
surayya-MS 62ed515
fix error message
surayya-MS 9c2002f
move package version
surayya-MS c30f7c0
apply suggestions
surayya-MS 94130b9
remove comment
surayya-MS 09a5a7b
small fix
surayya-MS 63be4f4
small change in xmake tests
surayya-MS 73b8443
apply same suggestion to the other xmake tests
surayya-MS 1bd2a25
refactor ParseSolutionHelper
surayya-MS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
309 changes: 243 additions & 66 deletions
309
src/Build.OM.UnitTests/Construction/SolutionFile_Tests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
166 changes: 166 additions & 0 deletions
166
src/Build.UnitTests/Construction/SolutionFile_NewParser_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading; | ||
using Microsoft.Build.Construction; | ||
using Microsoft.Build.Exceptions; | ||
using Microsoft.Build.Shared; | ||
using Microsoft.VisualStudio.SolutionPersistence; | ||
using Microsoft.VisualStudio.SolutionPersistence.Model; | ||
using Microsoft.VisualStudio.SolutionPersistence.Serializer; | ||
using Shouldly; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
#nullable disable | ||
|
||
namespace Microsoft.Build.UnitTests.Construction | ||
{ | ||
public class SolutionFile_NewParser_Tests | ||
{ | ||
public ITestOutputHelper TestOutputHelper { get; } | ||
|
||
public SolutionFile_NewParser_Tests(ITestOutputHelper testOutputHelper) | ||
{ | ||
TestOutputHelper = testOutputHelper; | ||
} | ||
|
||
/// <summary> | ||
/// Tests to see that all the data/properties are correctly parsed out of a Venus | ||
/// project in a .SLN. This can be checked only here because of AspNetConfigurations protection level. | ||
/// </summary> | ||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public void ProjectWithWebsiteProperties(bool convertToSlnx) | ||
{ | ||
string solutionFileContents = | ||
""" | ||
Microsoft Visual Studio Solution File, Format Version 9.00 | ||
# Visual Studio 2005 | ||
Project(`{E24C65DC-7377-472B-9ABA-BC803B73C61A}`) = `C:\WebSites\WebApplication3\`, `C:\WebSites\WebApplication3\`, `{464FD0B9-E335-4677-BE1E-6B2F982F4D86}` | ||
ProjectSection(WebsiteProperties) = preProject | ||
ProjectReferences = `{FD705688-88D1-4C22-9BFF-86235D89C2FC}|CSCla;ssLibra;ry1.dll;{F0726D09-042B-4A7A-8A01-6BED2422BD5D}|VCClassLibrary1.dll;` | ||
Frontpage = false | ||
Debug.AspNetCompiler.VirtualPath = `/publishfirst` | ||
Debug.AspNetCompiler.PhysicalPath = `..\rajeev\temp\websites\myfirstwebsite\` | ||
Debug.AspNetCompiler.TargetPath = `..\rajeev\temp\publishfirst\` | ||
Debug.AspNetCompiler.ForceOverwrite = `true` | ||
Debug.AspNetCompiler.Updateable = `false` | ||
Debug.AspNetCompiler.Debug = `true` | ||
Debug.AspNetCompiler.KeyFile = `debugkeyfile.snk` | ||
Debug.AspNetCompiler.KeyContainer = `12345.container` | ||
Debug.AspNetCompiler.DelaySign = `true` | ||
Debug.AspNetCompiler.AllowPartiallyTrustedCallers = `false` | ||
Debug.AspNetCompiler.FixedNames = `debugfixednames` | ||
Release.AspNetCompiler.VirtualPath = `/publishfirst_release` | ||
Release.AspNetCompiler.PhysicalPath = `..\rajeev\temp\websites\myfirstwebsite_release\` | ||
Release.AspNetCompiler.TargetPath = `..\rajeev\temp\publishfirst_release\` | ||
Release.AspNetCompiler.ForceOverwrite = `true` | ||
Release.AspNetCompiler.Updateable = `true` | ||
Release.AspNetCompiler.Debug = `false` | ||
VWDPort = 63496 | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|.NET = Debug|.NET | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{464FD0B9-E335-4677-BE1E-6B2F982F4D86}.Debug|.NET.ActiveCfg = Debug|.NET | ||
{464FD0B9-E335-4677-BE1E-6B2F982F4D86}.Debug|.NET.Build.0 = Debug|.NET | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal | ||
"""; | ||
|
||
SolutionFile solution = ParseSolutionHelper(solutionFileContents.Replace('`', '"'), convertToSlnx); | ||
|
||
solution.ProjectsInOrder.ShouldHaveSingleItem(); | ||
|
||
solution.ProjectsInOrder[0].ProjectType.ShouldBe(SolutionProjectType.WebProject); | ||
solution.ProjectsInOrder[0].ProjectName.ShouldBe(@"C:\WebSites\WebApplication3\"); | ||
// TODO: try set Relative path with a port http://localhost:8080/WebSites/WebApplication3/ | ||
surayya-MS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
solution.ProjectsInOrder[0].RelativePath.ShouldBe(@"C:\WebSites\WebApplication3\"); | ||
solution.ProjectsInOrder[0].Dependencies.Count.ShouldBe(2); | ||
solution.ProjectsInOrder[0].ParentProjectGuid.ShouldBeNull(); | ||
solution.ProjectsInOrder[0].GetUniqueProjectName().ShouldBe(@"C:\WebSites\WebApplication3\"); | ||
|
||
Hashtable aspNetCompilerParameters = solution.ProjectsInOrder[0].AspNetConfigurations; | ||
AspNetCompilerParameters debugAspNetCompilerParameters = (AspNetCompilerParameters)aspNetCompilerParameters["Debug"]; | ||
AspNetCompilerParameters releaseAspNetCompilerParameters = (AspNetCompilerParameters)aspNetCompilerParameters["Release"]; | ||
|
||
debugAspNetCompilerParameters.aspNetVirtualPath.ShouldBe(@"/publishfirst"); | ||
debugAspNetCompilerParameters.aspNetPhysicalPath.ShouldBe(@"..\rajeev\temp\websites\myfirstwebsite\"); | ||
debugAspNetCompilerParameters.aspNetTargetPath.ShouldBe(@"..\rajeev\temp\publishfirst\"); | ||
debugAspNetCompilerParameters.aspNetForce.ShouldBe(@"true"); | ||
debugAspNetCompilerParameters.aspNetUpdateable.ShouldBe(@"false"); | ||
debugAspNetCompilerParameters.aspNetDebug.ShouldBe(@"true"); | ||
debugAspNetCompilerParameters.aspNetKeyFile.ShouldBe(@"debugkeyfile.snk"); | ||
debugAspNetCompilerParameters.aspNetKeyContainer.ShouldBe(@"12345.container"); | ||
debugAspNetCompilerParameters.aspNetDelaySign.ShouldBe(@"true"); | ||
debugAspNetCompilerParameters.aspNetAPTCA.ShouldBe(@"false"); | ||
debugAspNetCompilerParameters.aspNetFixedNames.ShouldBe(@"debugfixednames"); | ||
|
||
releaseAspNetCompilerParameters.aspNetVirtualPath.ShouldBe(@"/publishfirst_release"); | ||
releaseAspNetCompilerParameters.aspNetPhysicalPath.ShouldBe(@"..\rajeev\temp\websites\myfirstwebsite_release\"); | ||
releaseAspNetCompilerParameters.aspNetTargetPath.ShouldBe(@"..\rajeev\temp\publishfirst_release\"); | ||
releaseAspNetCompilerParameters.aspNetForce.ShouldBe(@"true"); | ||
releaseAspNetCompilerParameters.aspNetUpdateable.ShouldBe(@"true"); | ||
releaseAspNetCompilerParameters.aspNetDebug.ShouldBe(@"false"); | ||
releaseAspNetCompilerParameters.aspNetKeyFile.ShouldBe(""); | ||
releaseAspNetCompilerParameters.aspNetKeyContainer.ShouldBe(""); | ||
releaseAspNetCompilerParameters.aspNetDelaySign.ShouldBe(""); | ||
releaseAspNetCompilerParameters.aspNetAPTCA.ShouldBe(""); | ||
releaseAspNetCompilerParameters.aspNetFixedNames.ShouldBe(""); | ||
|
||
List<string> aspNetProjectReferences = solution.ProjectsInOrder[0].ProjectReferences; | ||
aspNetProjectReferences.Count.ShouldBe(2); | ||
aspNetProjectReferences[0].ShouldBe("{FD705688-88D1-4C22-9BFF-86235D89C2FC}"); | ||
aspNetProjectReferences[1].ShouldBe("{F0726D09-042B-4A7A-8A01-6BED2422BD5D}"); | ||
} | ||
|
||
/// <summary> | ||
/// 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) | ||
{ | ||
solutionFileContents = solutionFileContents.Replace('\'', '"'); | ||
string solutionPath = FileUtilities.GetTemporaryFileName(".sln"); | ||
string slnxPath = solutionPath + "x"; | ||
try | ||
{ | ||
File.WriteAllText(solutionPath, solutionFileContents); | ||
if (convertToSlnx) | ||
{ | ||
ISolutionSerializer serializer = SolutionSerializers.GetSerializerByMoniker(solutionPath); | ||
SolutionModel solutionModel = serializer.OpenAsync(solutionPath, CancellationToken.None).Result; | ||
SolutionSerializers.SlnXml.SaveAsync(slnxPath, solutionModel, CancellationToken.None).Wait(); | ||
|
||
SolutionFile slnx = new SolutionFile { FullPath = slnxPath }; | ||
slnx.ParseUsingNewParser(); | ||
return slnx; | ||
} | ||
|
||
SolutionFile sln = SolutionFile.Parse(solutionPath); | ||
return sln; | ||
} | ||
finally | ||
{ | ||
File.Delete(solutionPath); | ||
|
||
if (convertToSlnx) | ||
{ | ||
File.Delete(slnxPath); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to self-service push to dotnet-public feed? https://dev.azure.com/dnceng/internal/_wiki/wikis/DNCEng%20Services%20Wiki/882/Updating-the-dotnet-public-feed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not on nuget.org yet so we'll have to either wait for that (@richardstanton?) or get a more manual push going.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/microsoft/vs-solutionpersistence/blob/main/README.md has a badge linked to nuget.org, but currently it's returning 404.
dotnet nuget push
missing somewhere :)