Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ private SolutionItemModel ReadProjectInfo(SolutionModel solution, ref StringToke
#pragma warning disable CS0618 // Type or member is obsolete (Temporaily create a potentially invalid solution folder until nested projects is interpreted.)
SolutionFolderModel folder = solution.CreateSlnFolder(name: displayName.ToString());
#pragma warning restore CS0618 // Type or member is obsolete

// Solution folders with duplicate ids should not error when reading sln files to preserve legacy behavior.
if (solution.FindItemById(projectId) is not null)
{
projectId = Guid.NewGuid();
this.tarnished = true;
}

folder.Id = projectId;
return folder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,35 @@ public async Task InvalidSlnxVersionAsync()
Assert.Equal(1, ex.Line);
Assert.Equal(2, ex.Column);
}

/// <summary>
/// The legacy sln solution parser would ignore duplicate folder guids.
/// Ensure this behavior is maintained.
/// </summary>
[Fact]
public async Task DuplicateFolderIdSlnAsync()
{
ResourceStream duplicateId = SlnAssets.LoadResource("Invalid/DuplicateFolderId.sln");
SolutionModel solution = await SolutionSerializers.SlnFileV12.OpenAsync(duplicateId.Stream, CancellationToken.None);

Assert.Equal(4, solution.SolutionFolders.Count);

Assert.NotNull(solution.SerializerExtension);
Assert.True(solution.SerializerExtension.Tarnished);
}

/// <summary>
/// Ensure the slnx parser does fail on duplicate folder guids.
/// </summary>
[Fact]
public async Task DuplicateFolderIdSlnxAsync()
{
ResourceStream duplicateId = SlnAssets.LoadResource("Invalid/DuplicateFolderId.slnx");
SolutionException ex = await Assert.ThrowsAsync<SolutionException>(
async () => _ = await SolutionSerializers.SlnXml.OpenAsync(duplicateId.Stream, CancellationToken.None));

Assert.StartsWith(string.Format(Errors.DuplicateItemRef_Args2, "11111111-1111-1111-1111-111111111111", nameof(SolutionFolderModel)), ex.Message);
Assert.Equal(3, ex.Line);
Assert.Equal(4, ex.Column);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Apple", "Apple", "{11111111-1111-1111-1111-111111111111}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mango", "Mango", "{11111111-1111-1111-1111-111111111111}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pear", "Pear", "{11111111-1111-1111-1111-111111111111}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Orange", "Orange", "{11111111-1111-1111-1111-111111111111}"
EndProject
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Solution>
<Folder Name="/Apple/" Id="11111111-1111-1111-1111-111111111111" />
<Folder Name="/Mango/" Id="11111111-1111-1111-1111-111111111111" />
<Folder Name="/Pear/" Id="11111111-1111-1111-1111-111111111111" />
<Folder Name="/Orange/" Id="11111111-1111-1111-1111-111111111111" />
</Solution>