Skip to content

Commit

Permalink
Merge pull request #13 from Cysharp/hotfix/FixRemovedProject
Browse files Browse the repository at this point in the history
Fix an error when a nested project was removed.
  • Loading branch information
mayuki authored Sep 29, 2020
2 parents e6c52d9 + 9dcf809 commit 236634d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Editor/SlnMerge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ private static Dictionary<string, SolutionTreeNode> BuildSolutionFlatTree(Soluti

if (!projectsByGuid.ContainsKey(projectGuid))
{
// Project has been removed from the base solution.
if (!solutionFile.Projects.ContainsKey(projectGuid))
{
continue;
}

projectsByGuid[projectGuid] = new SolutionTreeNode(solutionFile.Projects[projectGuid]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.cysharp.slnmerge",
"displayName": "SlnMerge",
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
"version": "1.2.0",
"version": "1.2.1",
"unity": "2018.4",
"description": "SlnMerge merges the solution files when generating solution file by Unity Editor.",
"keywords": ["Visual Studio", "sln", "IDE", "solution"],
Expand Down
52 changes: 52 additions & 0 deletions test/SlnMerge.Tests/SlnMergeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,58 @@ public void Merge_SolutionFolder_ExistedFolder_SectionExists()
".Trim().ReplacePathSeparators(), content.Trim());
}

[Fact]
public void Merge_SolutionFolder_ProjectHasBeenRemovedFromBaseSolution()
{
var baseSln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Unity.sln".ToCurrentPlatformPathForm(), @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 16
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Assembly-CSharp"", ""Assembly-CSharp.csproj"", ""{1E7138DC-D3E2-51A8-4059-67524470B2E7}""
EndProject
Global
GlobalSection(NestedProjects) = preSolution
{1E7138DC-D3E2-51A8-4059-67524470B2E7} = {F95BC0CF-E609-419F-B0A0-019BD5783670}
{1E7138DC-D3E2-51A8-4059-67524470B2E8} = {F95BC0CF-E609-419F-B0A0-019BD5783670}
EndGlobalSection
EndGlobal
".Trim());
var overlaySln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Server.sln".ToCurrentPlatformPathForm(), @"
Microsoft Visual Studio Solution File, Format Version 12.00
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Folder1"", ""Folder1"", ""{F95BC0CF-E609-419F-B0A0-019BD5783670}""
EndProject
Global
EndGlobal
".Trim());

// Merge without errors. NestedProject of removed projects remain in a merged solution.
var mergedSolutionFile = SlnMerge.Merge(
baseSln,
overlaySln,
new SlnMergeSettings()
{
NestedProjects = new[]
{
new SlnMergeSettings.NestedProject() { FolderPath = "Folder1", ProjectName = "Assembly-CSharp" },
}
},
SlnMergeNullLogger.Instance);
var content = mergedSolutionFile.ToFileContent();
Assert.Equal(@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 16
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Assembly-CSharp"", ""Assembly-CSharp.csproj"", ""{1E7138DC-D3E2-51A8-4059-67524470B2E7}""
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Folder1"", ""Folder1"", ""{F95BC0CF-E609-419F-B0A0-019BD5783670}""
EndProject
Global
GlobalSection(NestedProjects) = preSolution
{1E7138DC-D3E2-51A8-4059-67524470B2E7} = {F95BC0CF-E609-419F-B0A0-019BD5783670}
{1E7138DC-D3E2-51A8-4059-67524470B2E8} = {F95BC0CF-E609-419F-B0A0-019BD5783670}
EndGlobalSection
EndGlobal
".Trim().ReplacePathSeparators(), content.Trim());
}

[Fact]
public void Merge_SolutionItems()
{
Expand Down

0 comments on commit 236634d

Please sign in to comment.