Description
Related conversation: dotnet/docs#25603
Recently there was a conversation on how to target older frameworks in the templates, which again revealed that .NET templates in SDK are following 2 different approaches for distribution:
Common project and web/SPA project templates
The templates are shipped in separate packages: one package per TFM.
Examples:
microsoft.dotnet.common.projecttemplates.5.0
- the project common templates for .NET 5.0 (enables--framework net5.0
indotnet new
)microsoft.dotnet.web.projecttemplates.3.1
- the project common templates for .NET 3.1 (enables--framework netcoreapp3.1
indotnet new
)
Different TFM packages share same group identity, so installing several packages (for example microsoft.dotnet.web.projecttemplates.6.0
, microsoft.dotnet.web.projecttemplates.5.0
, microsoft.dotnet.web.projecttemplates.3.1
) doesn't lead to multiple templates being shown, but additional --framework
option to be available.
For example, if the templates above are installed the user has 3 options for --framework
: net6.0
, net5.0
, netcoreapp3.1
.
When certain SDK version is installed, it installs the template for corresponding TFM:
- if SDK 6.0 is installed, it installs
microsoft.dotnet.common.projecttemplates.6.0
andmicrosoft.dotnet.web.projecttemplates.6.0
, so user can only targetnet6.0
- if user additionally installs SDK 5.0, it installs
microsoft.dotnet.common.projecttemplates.5.0
andmicrosoft.dotnet.web.projecttemplates.5.0
, so now user can targetnet6.0
andnet5.0
via--framework
option when in .NET 6, and so on.
Additionally, all the template packs are available on NuGet.org, so as example if the user needs to use netcoreapp3.0
, he may install microsoft.dotnet.common.projecttemplates.3.0
manually and use it in dotnet new.
WPF, WinForms
The templates are shipped in single package with all supported TFMs listed in --framework
parameter
Example:
microsoft.dotnet.winforms.projecttemplates
for 5.0 hasnet5.0
,netcoreapp3.1
` frameworks available.microsoft.dotnet.winforms.projecttemplates
for 6.0 hasnet6.0
,net5.0
,netcoreapp3.1
frameworks available.
Different versions have same template identities, but different priority (precedence) - this allows later template version overwrite previous version.
This is different from behavior above:
When certain SDK version is installed, it installs the template for corresponding version:
- if SDK 6.0 is installed, it installs
microsoft.dotnet.winforms.projecttemplates
for 6.0, so user can targetnet6.0
,net5.0
,netcoreapp3.1
frameworks without installing corresponding SDKs. - if user additionally installs SDK 5.0, it installs
microsoft.dotnet.winforms.projecttemplates
for 5.0 which won't be used for SDK 6.0 because newer version is available; however will be used if the user runs dotnet new from SDK 5.0.
Additionally WPF and WinForms templates are not available on NuGet.org, however they seems to contain all supported TFMs, so that it should not be a problem, rather inconsistency.
Ideally it would be great to align the behavior across all the templates, so the users have same experience with SDK built-in templates.