dotnet / templating

This repo contains the Template Engine which is used by dotnet new
https://docs.microsoft.com/dotnet/
MIT License
1.63k stars 369 forks source link

dotnet new - duplicate templates and template uninstall recommendation #4128

Closed asears closed 2 years ago

asears commented 2 years ago

This will likely not happen in the wild too often but might be a minor security concern if "official" template identifier was replaced with another one. The workflow is a bit confusing since it allows for this scenario of duplicate template identifiers when installing templates.

I can see that it's been addressed by adding a '2' to the suffix of some templates.

Repro

Running dotnet new --install Microsoft.DotNet.Common.ItemTemplates::6.0.100 and then dotnet new editorconfig results in the following error which isn't so helpful in tracking down where the template was sourced from and the command to uninstall it.

Unable to resolve the template, these templates matched your input:

EditorConfig file   editorconfig                                              Config                                                              
EditorConfig fo...  editorconfig                                  [C#]                  

Suggestions

dotnet new --list --columns-all
EditorConfig file   editorconfig                                              item     Microsoft      Config                                      
EditorConfig fo...  editorconfig                                  [C#]        item     Will Huang                  

Fix

In my case, the correct answer was not below:

dotnet new --list --columns-alldotnet new --uninstall editorconfig
The template package 'editorconfig' is not found.
The template 'editorconfig' is included to the packages:
   Microsoft.DotNet.Common.ItemTemplates::6.0.100 (contains 7 templates)
   Duotify.Templates.DotNetNew::1.2.1 (contains 6 templates)
To uninstall the template package use:
   dotnet new --uninstall Microsoft.DotNet.Common.ItemTemplates

I used this to address

dotnet new --uninstall Duotify.Templates.DotNetNew

Template url: https://www.nuget.org/packages/Duotify.Templates.DotNetNew

Templates installed

This installed list probably isn't reflective of what's in the wild and is on one of my lab machines. Some of these might be out of date and contain security issues.

Template Name       Short Name                                    Language    Type     Author         Tags                                        
------------------  --------------------------------------------  ----------  -------  -------------  ------------------------------------------------------------------------------------------
ASP.NET Core Empty  web                                           [C#],F#     project  Microsoft      Web/Empty                                   
ASP.NET Core gR...  grpc                                          [C#]        project  Microsoft      Web/gRPC                                    
ASP.NET Core Te...  aspnet-core                                   [C#]                 Nikolay.IT     ASP.NET Core/Core/MVC/Template/Web          
ASP.NET Core We...  webapi                                        [C#],F#     project  Microsoft      Web/WebAPI                                  
ASP.NET Core We...  webapi2                                       [C#]        project  Microsoft      Web/WebAPI                                  
ASP.NET Core We...  webapp,razor                                  [C#]        project  Microsoft      Web/MVC/Razor Pages                         
ASP.NET Core We...  webapp2,razor2                                [C#]        project  Microsoft      Web/MVC/Razor Pages                         
ASP.NET Core We...  mvc2                                          [C#]        project  Microsoft      Web/MVC                                     
ASP.NET Core We...  mvc                                           [C#],F#     project  Microsoft      Web/MVC                                     
ASP.NET Core wi...  angular                                       [C#]        project  Microsoft      Web/MVC/SPA                                 
ASP.NET Core wi...  react                                         [C#]        project  Microsoft      Web/MVC/SPA                                 
ASP.NET Core wi...  reactredux                                    [C#]        project  Microsoft      Web/MVC/SPA                                 
Avalonia .NET C...  avalonia.app                                  [C#]        project  AvaloniaUI     ui/xaml                                     
Avalonia .NET C...  avalonia.mvvm                                 [C#]        project  AvaloniaUI     ui/xaml                                     
Avalonia UserCo...  avalonia.usercontrol                          [C#]        item     AvaloniaUI     ui/xaml                                     
Avalonia Window     avalonia.window                               [C#]        item     AvaloniaUI     ui/xaml                                     
Azure Functions     func2                                         [C#]        project  Microsoft      Azure Functions/Solution                    
Azure Functions     func                                          [C#],F#     project  Microsoft      Azure Functions/Solution                    
Blazor Hero - C...  BlazorHero.CleanArchitecture                  [C#]        project  Mukesh Mur...  Web/Blazor/WebAssembly/WebApi/CleanArchitecture
Blazor Server App   blazorserver                                  [C#]        project  Microsoft      Web/Blazor                                  
Blazor Server A...  blazorserver2                                 [C#]        project  Microsoft      Web/Blazor                                  
Blazor WebAssem...  blazorwasm                                    [C#]        project  Microsoft      Web/Blazor/WebAssembly/PWA                  
Blazor WebAssem...  blazorwasm2                                   [C#]        project  Microsoft      Web/Blazor/WebAssembly                      
Class               vitalelement.CPlusPlus.class                  C++         item     VitalElement   class/code                                  
Class               vitalelement.csharp.class                     [C#]        item     VitalElement   class/code                                  
Class Library       classlib                                      [C#],F#,VB  project  Microsoft      Common/Library                              
Console App         console                                       [C#],F#,VB  project  Microsoft      Common/Console                              
Console Applica...  console.app                                   C++         project  VitalElement   console/cpp                                 
Cross-Platform App  unoapp                                        [C#]        project  Uno Platform   Cross-platform/Uno Platform/Android/iOS/Windows/macOS/Linux/Tizen/WebAssembly/dotnet-new
Cross-Platform ...  unoapp-prism                                  [C#]        project  Uno Platform   Cross-platform/Uno Platform/Prism/Android/iOS/Windows/macOS/WebAssembly/dotnet-new
Cross-Platform ...  unoapp-winui                                  [C#]        project  Uno Platform   Cross-platform/Uno Platform/Android/iOS/Windows/macOS/Linux/WebAssembly/WinUI/dotnet-new
Cross-Platform ...  unolib                                        [C#]        project  Uno Platform   Cross-platform/Uno Platform/Library/Android/iOS/Windows/macOS/Linux/WebAssembly/dotnet-new
Cross-Platform ...  unoapp-uitest                                 [C#]        project  Uno Platform   Cross-platform/Uno Platform/UITest/Android/iOS/WebAssembly/dotnet-new
Cross-Runtime L...  unolib-crossruntime                           [C#]        project  Uno Platform   Cross-platform/Uno Platform/Library/Android/iOS/Windows/macOS/Linux/WebAssembly/dotnet-new
Database table      table                                         SQL         item     MSBuild.Sd...  Database/SqlServer/Table                    
Database view       view                                          SQL         item     MSBuild.Sd...  Database/SqlServer/View                     
dotnet gitignor...  gitignore                                                 item     Microsoft      Config                                      
Dotnet local to...  tool-manifest                                             item     Microsoft      Config                                      
EditorConfig file   editorconfig                                              item     Microsoft      Config                                      
EditorConfig fo...  editorconfig                                  [C#]        item     Will Huang                                                 
global.json file    globaljson                                                item     Microsoft      Config                                      
Go Project (Bas...  gobasic                                       Go          project  Will Huang                                                 
Go Project (CLI)    go                                            Go          project  Will Huang                                                 
Go Project (Ful...  gofull                                        Go          project  Will Huang                                                 
Go Project (Lib...  golib                                         Go          project  Will Huang                                                 
Go Project with...  gogin                                         Go          project  Will Huang                                                 
HotChocolate Gr...  graphql                                       [C#]        project  Michael Staib  Web/GraphQL                                 
HotChocolate Gr...  starwars                                      [C#]        project  Michael Staib  ChilliCream/HotChocolate/Demos              
Inline function     inlinefunc                                    SQL         item     MSBuild.Sd...  Database/SqlServer/InlineFunction           
Interface           vitalelement.csharp.interface                 [C#]        item     VitalElement   interface/code                              
Lambda ASP.NET ...  serverless.AspNetCoreWebAPI                   [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Lambda ASP.NET ...  serverless.image.AspNetCoreWebAPI             [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Lambda ASP.NET ...  serverless.AspNetCoreWebApp                   [C#]        project  AWS            AWS/Lambda/Serverless                       
Lambda Custom R...  lambda.CustomRuntimeFunction                  [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda Detect I...  lambda.DetectImageLabels                      [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda DynamoDB...  serverless.DynamoDBBlogAPI                    [C#]        project  AWS            AWS/Lambda/Serverless                       
Lambda Empty Fu...  lambda.EmptyFunction                          [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda Empty Fu...  lambda.image.EmptyFunction                    [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda Empty Se...  serverless.EmptyServerless                    [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Lambda Empty Se...  serverless.image.EmptyServerless              [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Lambda Giraffe ...  serverless.Giraffe                            F#          project  AWS            AWS/Lambda/Serverless                       
Lambda Simple A...  lambda.SimpleApplicationLoadBalancerFunction  [C#]        project  AWS            AWS/Lambda/Function                         
Lambda Simple D...  lambda.DynamoDB                               [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda Simple K...  lambda.KinesisFirehose                        [C#]        project  AWS            AWS/Lambda/Function                         
Lambda Simple K...  lambda.Kinesis                                [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda Simple S...  lambda.S3                                     [C#],F#     project  AWS            AWS/Lambda/Function                         
Lambda Simple S...  lambda.SNS                                    [C#]        project  AWS            AWS/Lambda/Function                         
Lambda Simple S...  lambda.SQS                                    [C#]        project  AWS            AWS/Lambda/Function                         
Lean.Algorithm....  lean                                          [C#]        project  cphillips83    Lean/Console/C#9                            
LESS Style Sheet    less                                                      item     Microsoft      Web/Style                                   
Lex Book Trip S...  lambda.LexBookTripSample                      [C#]        project  AWS            AWS/Lambda/Function                         
Microsoft Teams...  teamsapp                                      [C#]        project  Microsoft      Web/Microsoft Teams                         
MSTest Test Pro...  mstest                                        [C#],F#,VB  project  Microsoft      Test/MSTest                                 
MVC ViewImports     viewimports                                   [C#]        item     Microsoft      Web/ASP.NET                                 
MVC ViewStart       viewstart                                     [C#]        item     Microsoft      Web/ASP.NET                                 
NuGet Config        nugetconfig                                               item     Microsoft      Config                                      
NUnit 3 Test Item   nunit-test                                    [C#],F#,VB  item     Aleksei Kh...  Test/NUnit                                  
NUnit 3 Test Pr...  nunit                                         [C#],F#,VB  project  Aleksei Kh...  Test/NUnit                                  
Order Flowers C...  lambda.OrderFlowersChatbot                    [C#]        project  AWS            AWS/Lambda/Function                         
osu!framework e...  osu-framework-game                            [C#]        project  ppy Pty Ltd    Console                                     
osu!framework f...  osu-framework-flappy-game                     [C#]        project  ppy Pty Ltd    Console                                     
PowerShell Stan...  psmodule                                      [C#]        project  Microsoft ...  Library/PowerShell/Module                   
Protocol Buffer...  proto                                                     item     Microsoft      Web/gRPC                                    
Razor Class Lib...  razorclasslib                                 [C#]        project  Microsoft      Web/Razor/Library/Razor Class Library       
Razor Component     razorcomponent                                [C#]        item     Microsoft      Web/ASP.NET                                 
Razor Page          page                                          [C#]        item     Microsoft      Web/ASP.NET                                 
Roslyn source g...  roslyn-sg                                     [C#]        project  Roslyn Tem...  roslyn                                      
SAFE-Stack Web ...  SAFE                                          F#          project  Tomasz Hei...  Web/Saturn/Azure/Fable/Elmish               
SAFEr Web App v...  SAFEr                                         F#          project  Roman Prov...  Web/Giraffe/Azure/Fable/Elmish/Farmer       
Scalar Function     scalarfunc                                    SQL         item     MSBuild.Sd...  Database/SqlServer/ScalarFunction           
SCSS Style Shee...  scss                                                      item     Microsoft      Web/Style                                   
Serverless Dete...  serverless.DetectImageLabels                  [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Serverless Simp...  serverless.S3                                 [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Serverless WebS...  serverless.WebSocketAPI                       [C#]        project  AWS            AWS/Lambda/Serverless                       
Solution File       sln                                                                Microsoft      Solution                                    
SQL Server Data...  sqlproj                                       SQL         project  MSBuild.Sd...  Database/SqlServer                          
Step Functions ...  serverless.StepFunctionsHelloWorld            [C#],F#     project  AWS            AWS/Lambda/Serverless                       
Stored procedure    sproc                                         SQL         item     MSBuild.Sd...  Database/SqlServer/StoredProcedure          
Table-valued Fu...  tablefunc                                     SQL         item     MSBuild.Sd...  Database/SqlServer/TableFunction            
TypeScript file     tsfile                                                    item     Microsoft      Web/Script                                  
Uno Platform We...  wasmxfhead                                    [C#]        project  Uno Platform   Cross-platform/Uno Platform/Xamarin.Forms/WebAssembly/dotnet-new
User-defined da...  uddt                                          SQL         item     MSBuild.Sd...  Database/SqlServer/UserDefinedDataType      
User-defined ta...  udtt                                          SQL         item     MSBuild.Sd...  Database/SqlServer/UserDefinedTableType     
Web Config          webconfig                                                 item     Microsoft      Config                                      
WebSharper 4 Cl...  websharper-web                                [C#],F#     project  IntelliFac...  WebSharper/Web                              
WebSharper 4 Ex...  websharper-ext                                F#          project  IntelliFac...  WebSharper                                  
WebSharper 4 Ht...  websharper-html                               [C#],F#     project  IntelliFac...  WebSharper/Web                              
WebSharper 4 Li...  websharper-lib                                [C#],F#     project  IntelliFac...  WebSharper                                  
WebSharper 4 Proxy  websharper-prx                                [C#],F#     project  IntelliFac...  WebSharper                                  
WebSharper 4 Si...  websharper-spa                                [C#],F#     project  IntelliFac...  WebSharper/Web                              
Windows Forms App   winforms                                      [C#],VB     project  Microsoft      Common/WinForms                             
Windows Forms C...  winformslib                                   [C#],VB     project  Microsoft      Common/WinForms                             
Windows Forms C...  winformscontrollib                            [C#],VB     project  Microsoft      Common/WinForms                             
Worker Service      worker                                        [C#],F#     project  Microsoft      Common/Worker/Web                           
Worker Service      worker2                                       [C#]        project  Microsoft      Common/Worker/Web                           
WPF Application     wpf                                           [C#],VB     project  Microsoft      Common/WPF                                  
WPF Class library   wpflib                                        [C#],VB     project  Microsoft      Common/WPF                                  
WPF Custom Cont...  wpfcustomcontrollib                           [C#],VB     project  Microsoft      Common/WPF                                  
WPF User Contro...  wpfusercontrollib                             [C#],VB     project  Microsoft      Common/WPF                                  
XrmFramework        xrmPluginProject                              [C#]        project  Christophe...  Common/Library                              
XrmFramework        xrmSolution                                   [C#]        project  Christophe...  Common/Library                              
xUnit Test Project  xunit                                         [C#],F#,VB  project  Microsoft      Test/xUnit  
vlada-shubina commented 2 years ago

@asears

Thank you for the issue, indeed most of concerns are valid.

Some suggestion on how to address the duplicate template error with an --uninstall suggestion or some warning on install might be useful for devs. This is a bug, I will address it. Other cases suggest uninstalling the template as possible workaroung

I was still unable to see the source of this template with all columns enabled. Could include the nuget package identifier in the column list.

This is tracked in https://github.com/dotnet/templating/issues/2909.

the recommendation could provide some security slant to the recommendations for Microsoft.DotNet.Common.ItemTemplates and others distributed by Microsoft vs. community or organization templates. It shouldn't recommend uninstalling an official template.

Uninstalling official template is not possible, that's why we are considering https://github.com/dotnet/templating/issues/4135 for I while (i extracted it to separate issue so we can track it separately). Author column may guide you on who authored the template, but it is not shown by default. @baronfel should we consider more visible way to distinguish Microsoft templates from 3rd party when showing the list?

baronfel commented 2 years ago

I think the message could be changed to not suggest uninstalling Microsoft-authored templates, and perhaps the message when uninstalling a Microsoft-authored should be updated to let the user know this is disallowed. I'm not sure that denoting Microsoft templates in any other way than the Author column is going to be something that's generally useful, though.

vlada-shubina commented 2 years ago

Some suggestion on how to address the duplicate template error with an --uninstall suggestion or some warning on install might be useful for devs. This is a bug, I will address it. Other cases suggest uninstalling the template as possible workaroung

The problem above was fixed while migrating to new parser, the new output is below:

Unable to resolve the template, the following installed templates are conflicting:
Identity                         Template Name       Short Name     Language  Author      Package
%TABLE HEADER DELIMITER%
Invalid.SameShortName.TemplateA  Invalid.SameSho...  sameshortname            Test Asset  %TEMPLATE LOCATION%
Invalid.SameShortName.TemplateB  Invalid.SameSho...  sameshortname            Test Asset  %TEMPLATE LOCATION%

Uninstall the template packages containing the templates to keep only one template from the list or add the template options which differentiate the template to run.

This output suggests to uninstall the package in case of the conflict. This is not yet perfect, as still there is no way to run the templates that have same short name. We plan to improve this behavior in https://github.com/dotnet/templating/issues/4135.

I was still unable to see the source of this template with all columns enabled. Could include the nuget package identifier in the column list.

This is tracked in https://github.com/dotnet/templating/issues/2909, please follow it.

I'm closing this issue now, the remaining work will be done in https://github.com/dotnet/templating/issues/4135 and https://github.com/dotnet/templating/issues/2909.