`dotnet new -i *.nupkg` doesn't install the template
See original GitHub issueI have a solution which I wish turn it into a template. I added .template.config
, template.json
and TemplatePack.csproj
and I can install the template using file path, e.g dotnet new -i C:\MyTemplate
. but I can not install it using generated .nupkg
.
I could not find any way to tell dotnet new
to show me the possible error(s).
BTW, after running dotnet new -i MyTemplate.nupkg
the list of templates shown in the terminal.
TemplatePack.csproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>1.0</PackageVersion>
<PackageId>MyTemplate</PackageId>
<Title>MyTemplate</Title>
<Authors>Me</Authors>
<Description>MyTemplate.</Description>
<PackageTags>dotnet-new;templates</PackageTags>
<TargetFramework>net5.0</TargetFramework>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>
<NoWarn>$(NoWarn);NU5128</NoWarn>
</PropertyGroup>
<ItemGroup>
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />
<Compile Remove="**\*" />
</ItemGroup>
</Project>
template.json
:
{
"$schema": "http://json.schemastore.org/template",
"author": "Me",
"classifications": [
"Web",
"ASP.NET"
],
"tags": {
"language": "C#"
},
"identity": "MyTemplate",
"name": "MyTemplate",
"shortName": "mywebapp",
"sourceName": "MyTemplate",
"preferNameDirectory": true
}
MyTemplate is not real, in the actual files I wrote something else.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Installing a template with dotnet new -i from custom Nuget ...
I have a template published to our own Nuget feed. I'm trying to install it with dotnet new -i , but none of...
Read more >Installing dotnet new template not working from NuGet ...
I have a template which is packaged and deployed to an Azure Devops NuGet Feed. I can't install this template when I use...
Read more >dotnet new install - .NET CLI
The dotnet new install command installs a template package from the PATH or NUGET_ID provided. If you want to install a specific version...
Read more >How to install and use a project template using dotnet CLI
Unzip the .zip. then in your terminal, navigate to the template folder (it should contain a folder named .template.config ). Then run dotnet...
Read more >How to Create Your .NET Project Template
Let's install it locally by running the following command in the templates-playground/templates/auth0-webapp folder: dotnet new --install . This command lets ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dehghani-mehdi This is the line you need to fix, it now includes the
template
folder (excludingbin
andobj
internal folders) to nuget content:just add folder
.template.config
to include there too.Only small amount of all nuget packages consists templates, so no reason to have a warning.
Some docs about writing a
.csproj
for packing: one, two.@dehghani-mehdi The number of templates does not matter in the example, it might be 1,2, etc. I am more or less confident that fixing folders structure would resolve your problem. Here is reasoning:
The main problem with your nuget package is complete absence of
.template.config
folder in it. It is not included into package by giventemplatepack.csproj
. Thus, the nuget package has 0 templates, nothing is installed, and that is correct behavior.The miscommunication between folders structure and what is in
.csproj
file is the reason for absence of.template.config
folder in nuget.What I suggested is not the only way to fix, right, so your previous working version could have been indeed different. You can also fix it in
.csproj
file. Or you can move.template.config
totemplates
folder. But I’d better keep the folders structure as what is in documentation.