Skip to content

Commit

Permalink
sln-add: Only add guid on slnv12 files (#45366)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpopMSFT authored and edvilme committed Dec 10, 2024
1 parent 4c330ee commit 6e259bb
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Cli/dotnet/commands/dotnet-sln/add/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private async Task AddProjectsToSolutionAsync(string solutionFileFullPath, IEnum

try
{
AddProject(solution, relativePath, projectPath, solutionFolder);
AddProject(solution, relativePath, projectPath, solutionFolder, serializer);
}
catch (InvalidProjectFileException ex)
{
Expand All @@ -130,7 +130,7 @@ private async Task AddProjectsToSolutionAsync(string solutionFileFullPath, IEnum
await serializer.SaveAsync(solutionFileFullPath, solution, cancellationToken);
}

private void AddProject(SolutionModel solution, string solutionRelativeProjectPath, string fullPath, SolutionFolderModel? solutionFolder)
private void AddProject(SolutionModel solution, string solutionRelativeProjectPath, string fullPath, SolutionFolderModel? solutionFolder, ISolutionSerializer serializer = null)
{
// Open project instance to see if it is a valid project
ProjectRootElement projectRootElement = ProjectRootElement.Open(fullPath);
Expand All @@ -153,7 +153,7 @@ private void AddProject(SolutionModel solution, string solutionRelativeProjectPa
// Add settings based on existing project instance
ProjectInstance projectInstance = new ProjectInstance(projectRootElement);
string projectInstanceId = projectInstance.GetProjectId();
if (!string.IsNullOrEmpty(projectInstanceId))
if (!string.IsNullOrEmpty(projectInstanceId) && serializer is ISolutionSerializer<SlnV12SerializerSettings>)
{
project.Id = new Guid(projectInstanceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<Platform Solution="*|x64" Project="x64" />
<Platform Solution="*|x86" Project="x86" />
</Project>
<Project Path="Lib/Lib.csproj" Id="__LIB_PROJECT_GUID__"/>
<Project Path="Lib/Lib.csproj" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="Lib/Lib.csproj" Id="__LIB_PROJECT_GUID__" />
<Project Path="Lib/Lib.csproj" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platform Name="x86" />
</Configurations>
<Folder Name="/src/">
<Project Path="src/Lib/Lib.csproj" Id="__LIB_PROJECT_GUID__" />
<Project Path="src/Lib/Lib.csproj" />
</Folder>
<Project Path="App.csproj">
<Platform Solution="*|x64" Project="x64" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<Platform Solution="*|x64" Project="x64" />
<Platform Solution="*|x86" Project="x86" />
</Project>
<Project Path="src/Lib/Lib.csproj" Id="__LIB_PROJECT_GUID__"/>
<Project Path="src/Lib/Lib.csproj" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platform Name="x86" />
</Configurations>
<Folder Name="/TestFolder/">
<Project Path="src/Lib/Lib.csproj" Id="__LIB_PROJECT_GUID__" />
<Project Path="src/Lib/Lib.csproj" />
</Folder>
<Project Path="App.csproj">
<Platform Solution="*|x64" Project="x64" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="ProjectWithAdditionalConfigs/ProjectWithAdditionalConfigs.csproj" Id="a302325b-d680-4c0e-8680-7ae283981624">
<Project Path="ProjectWithAdditionalConfigs/ProjectWithAdditionalConfigs.csproj">
<BuildType Solution="Foo Bar|*" Project="FooBar" />
<Platform Solution="*|x64" Project="x64" />
<Platform Solution="*|x86" Project="x86" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="ProjectWithMatchingConfigs/ProjectWithMatchingConfigs.csproj" Id="c9601ca2-db64-4fb6-b463-368c7764bf0d">
<Project Path="ProjectWithMatchingConfigs/ProjectWithMatchingConfigs.csproj">
<BuildType Solution="Foo Bar|*" Project="FooBar" />
<Platform Solution="*|x64" Project="x64" />
<Platform Solution="*|x86" Project="x86" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="ProjectWithoutMatchingConfigs/ProjectWithoutMatchingConfigs.csproj" Id="c49b64de-4401-4825-8a88-10dcb5950e57">
<Project Path="ProjectWithoutMatchingConfigs/ProjectWithoutMatchingConfigs.csproj" >
<BuildType Solution="Foo Bar|*" Project="Debug" />
</Project>
</Solution>

0 comments on commit 6e259bb

Please sign in to comment.