Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to uninstall `dotnet new` via folder template?

Tags:

.net-core

Is there a special method for uninstalling a folder-template dotnet new project beyond what is described in the .NET Core docs?

dotnet new -u <FILE_SYSTEM_DIRECTORY>

Steps

After setting up a folder template for dotnet new, I installed it (per docs).

dotnet new --install ./some-template-folder/

This successfully puts the template in place for use with dotnet new {shortName}.

The template "Some Template Name" was created successfully.

Unfortunately, I cannot uninstall that template afterwards using the appropriate command (per docs)

dotnet new --uninstall ./some-template-folder/

Resulting in the following output instead.

Could not find something to uninstall called '.\some-template-folder\'.

Details

If it helps, here is the folder's minimal template.json file contained in the folder's .template.config sub-folder.

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Some Author",
    "classifications": [ "Some", "Various", "Search Keywords" ],
    "identity": "Some.Identity",
    "shortName": "name-used-in-dotnetnew",
    "name": "Some Template Name"
}

Filed bug

dotnet/templating#1226

like image 721
patridge Avatar asked Aug 24 '17 15:08

patridge


1 Answers

This turned out to be an issue with the state of the templates specific to my machine. After doing a dotnet new --debug:reinit to revert the templates to their freshly installed state, the issue went away.

Potential issues

While my issue was machine-specific, there were some elements unique to path uninstalls via dotnet new --uninstall <path> that could also cause this issue.

Make paths absolute

While you can install from a relative path (e.g., dotnet new --install ./some-template), you must uninstall from a fully qualified path.

dotnet new --uninstall C:\full\path\to\some-template

Avoid terminal slash

Additionally, when you do pass in a fully qualified path to --uninstall, do not include the terminal slash that your command-line environment may auto-include when you tab complete the path.

dotnet new --uninstall C:\full\path\to\some-template #<-- no terminal \ here

[Edit: new uninstall list option]

While all of the below details are still currently accurate, they have now added a system for determining exactly what uninstall string is required. Run the uninstall command without any parameters to see a list of installed templates listed by the exact string required to uninstall them.

dotnet new --uninstall

And it will output a list like this, with short names for NuGet packages and full paths for locally installed templates.

Template Instantiation Commands for .NET Core CLI

Currently installed items:
 Microsoft.DotNet.Common.ItemTemplates
 ...
 dotnet-new-project-helper
 C:\full\path\to\some-template

You could then uninstall that final template with the listed path.

dotnet new --uninstall C:\full\path\to\some-template
like image 193
patridge Avatar answered Oct 30 '22 11:10

patridge