templating: Creating new solution using "dotnet new sln" in .NET 5.0.201 SDK has wrong/invalid solution version number

Problem

When we create new solution using “dotnet new sln” in .NET 5.0.201 SDK has wrong/invalid solution version number in the VisualStudioVersion. This version is invalid, because there’s no Visual Studio solution has higher version than “16.6..” at this moment (at least in observed 16.9.x)

Reason: this version cannot be used to enforce minimum version of Visual Studio to open.

Steps to reproduce

The steps are:

  1. Create new solution using dotnet new sln. Example: dotnet new sln -n SolutionNET5
  2. Open the solution file in notepad other text editor
  3. The version of the VisualStudioVersion is 16.6.30114.105
  4. Update the MinimumVisualStudioVersion to be the same as VisualStudioVersion
  5. Open the solution in Visual Studio 2019 16.9.x (error happened in 16.9.0, 16.9.1, 16.9.2)

Full contents after dotnet new sln is:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.6.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
                Debug|x64 = Debug|x64
                Debug|x86 = Debug|x86
                Release|Any CPU = Release|Any CPU
                Release|x64 = Release|x64
                Release|x86 = Release|x86
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
EndGlobal

The error after I update the MinimumVisualStudioVersion value to 16.6.30114.105 is:

image

If I use .NET Core 3.1.406 SDK to create new solution, I have this:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
                Debug|x64 = Debug|x64
                Debug|x86 = Debug|x86
                Release|Any CPU = Release|Any CPU
                Release|x64 = Release|x64
                Release|x86 = Release|x86
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
EndGlobal

And this file can always be opened by Visual Studio 16.8.x to 16.9.x without any error, as the MinimumVisualStudioVersion is still valid solution version.

If I use VS 2019 16.9.2 to create new blank solution, I get this:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 10.0.40219.1
Global
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
        GlobalSection(ExtensibilityGlobals) = postSolution
                SolutionGuid = {195F37AF-9751-4154-9434-59DB85FFDC3F}
        EndGlobalSection
EndGlobal

Update that file by setting MinimumVisualStudioVersion to 16.0.31112.23, like below:.

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 16.0.31112.23
Global
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
        GlobalSection(ExtensibilityGlobals) = postSolution
                SolutionGuid = {195F37AF-9751-4154-9434-59DB85FFDC3F}
        EndGlobalSection
EndGlobal

Open this file in Visual Studio, and it will open nicely!

Notice the VisualStudioVersion generated by 16.9.2. It is versioned as 16.0.31112.23, so VS will not see the version generated by .NET Core 5.0.201 SDK as valid version, because version 16.6.30114.105 is definitely higher than the current generated version of 16.9,2.

Suggestion

Please fix this solution creation version in .NET 5.0.201 SDK!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (14 by maintainers)

Commits related to this issue

Most upvoted comments

As far as I understand it, you have to manually edit the solution file in order to run into a problem here.

I’m also not clear on why you are trying to enforce a minimum VS version in the sln file. I don’t think this is very common. Using a global.json file like the following might do what you want instead:

{
  "sdk": {
    "version": "5.0.100",
    "rollForward": "latestMajor"
  }
}