Skip to content

Commit

Permalink
Always honor ProjectGuid, if provided (#615)
Browse files Browse the repository at this point in the history
* Always honor ProjectGuid, if provided

* Upgrade System.Text.Json (#616)

Co-authored-by: Snorri Gislason <[email protected]>

* Always honor ProjectGuid, if provided

* Don't require ProjectGuid for legacy projects

---------

Co-authored-by: Snorri Gislason <[email protected]>
  • Loading branch information
snorrk and Snorri Gislason authored Oct 9, 2024
1 parent e322bb9 commit a4a2396
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/Microsoft.VisualStudio.SlnGen/SlnProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,25 +293,28 @@ internal static bool GetIsDeployable(Project project, string projectFileExtensio
/// <returns>The GUID of the specified project.</returns>
internal static Guid GetProjectGuid(Project project, bool isUsingMicrosoftNETSdk)
{
Guid projectGuid = Guid.NewGuid();
Guid projectGuid;

if (!isUsingMicrosoftNETSdk && !Guid.TryParse(project.GetPropertyValueOrDefault(MSBuildPropertyNames.ProjectGuid, projectGuid.ToString()), out projectGuid))
{
string projectGuidValue = project.GetPropertyValueOrDefault(MSBuildPropertyNames.ProjectGuid, projectGuid.ToString());
string projectGuidValue = project.GetPropertyValue(MSBuildPropertyNames.ProjectGuid);
bool projectGuidIsEmpty = string.IsNullOrEmpty(projectGuidValue);

if (!Guid.TryParse(projectGuidValue, out projectGuid))
{
throw new InvalidProjectFileException(
projectFile: project.FullPath,
lineNumber: 0,
columnNumber: 0,
endLineNumber: 0,
endColumnNumber: 0,
message: $"The {MSBuildPropertyNames.ProjectGuid} property value \"{projectGuidValue}\" is not a valid GUID.",
errorSubcategory: null,
errorCode: null,
helpKeyword: null);
}
// If a ProjectGuid is provided it should be honored (regardless of project style) and must be valid
if (projectGuidIsEmpty)
{
projectGuid = Guid.NewGuid();
}
else if (!Guid.TryParse(projectGuidValue, out projectGuid))
{
throw new InvalidProjectFileException(
projectFile: project.FullPath,
lineNumber: 0,
columnNumber: 0,
endLineNumber: 0,
endColumnNumber: 0,
message: $"The {MSBuildPropertyNames.ProjectGuid} property value \"{projectGuidValue}\" is not a valid GUID.",
errorSubcategory: null,
errorCode: null,
helpKeyword: null);
}

return projectGuid;
Expand Down

0 comments on commit a4a2396

Please sign in to comment.