Skip to content
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

sln-add: Only add guid on slnv12 files #45366

Merged
merged 3 commits into from
Dec 10, 2024
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
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>