Skip to content

Commit

Permalink
fix: support parsing solution configuration mappings for projects whi…
Browse files Browse the repository at this point in the history
…ch don't have a platform (#25)

* Support parsing solution configuration mappings for projects which don't have a platform
Fixes #24

* Fixed coding style
Moved sln file contents to external file
  • Loading branch information
icnocop authored Aug 25, 2023
1 parent ede0246 commit 1f7285f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
45 changes: 45 additions & 0 deletions src/SlnParser.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,51 @@ public void Should_Be_Able_To_Parse_TestSln_Solution_Correctly()
.Contain(file => file.Name == "testNested1.txt");
}

[Fact]
public void Parse_WithProjectWithoutPlatform_IsParsedCorrectly()
{
var solutionFile = LoadSolution("ProjectWithoutPlatform");

var sut = new SolutionParser();

var solution = sut.Parse(solutionFile);

solution
.ConfigurationPlatforms
.Should()
.HaveCount(1);

var configurationPlatform = solution
.ConfigurationPlatforms
.Single();

configurationPlatform
.Configuration
.Should()
.Be("SolutionConfigurationName");

configurationPlatform
.Platform
.Should()
.Be("SolutionPlatformName");

solution
.AllProjects
.Should()
.HaveCount(1);

solution
.Projects
.Should()
.HaveCount(1);

var project = solution.Projects.Single();
project.Id.Should().Be("D5BDBC46-CEAF-4C92-8335-31450B76914F");
project.Name.Should().Be("Test");
project.TypeGuid.Should().Be("D183A3D8-5FD8-494B-B014-37F57B35E655");
project.Type.Should().Be(ProjectType.Unknown);
}

private static FileInfo LoadSolution(string solutionName)
{
var solutionFileName = $"./Solutions/{solutionName}.sln";
Expand Down
8 changes: 1 addition & 7 deletions src/SlnParser.Tests/SlnParser.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
</ItemGroup>

<ItemGroup>
<None Include="Solutions\SlnParser.sln">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<None Include="Solutions\TestSln.sln">
<None Include="Solutions\*.sln">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions src/SlnParser.Tests/Solutions/ProjectWithoutPlatform.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{D183A3D8-5FD8-494B-B014-37F57B35E655}") = "Test", "Test.dtproj", "{D5BDBC46-CEAF-4C92-8335-31450B76914F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
SolutionConfigurationName|SolutionPlatformName = SolutionConfigurationName|SolutionPlatformName
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D5BDBC46-CEAF-4C92-8335-31450B76914F}.SolutionConfigurationName|SolutionPlatformName.ActiveCfg = ProjectConfigurationName
{D5BDBC46-CEAF-4C92-8335-31450B76914F}.SolutionConfigurationName|SolutionPlatformName.Build.0 = ProjectConfigurationName
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static ProjectConfigurationPlatform ParseConfigurationPlatform(string li
{
// c.f.: https://regexr.com/65t6u
const string pattern =
@"((?<projectId>\{[A-Za-z0-9\-]+\}).)?(?<name>.+) = (?<buildConfiguration>.+)\|(?<buildPlatform>.+)";
@"((?<projectId>\{[A-Za-z0-9\-]+\}).)?(?<name>.+) = (?<buildConfiguration>.+?)(?:\|(?<buildPlatform>.+))?$";

var match = Regex.Match(line, pattern);
if (!match.Success)
Expand Down

0 comments on commit 1f7285f

Please sign in to comment.