question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`dotnet new -i *.nupkg` doesn't install the template

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AR-Maycommented, Jul 26, 2021

@dehghani-mehdi This is the line you need to fix, it now includes the template folder (excluding bin and obj internal folders) to nuget content:

<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />

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.

1reaction
AR-Maycommented, Jul 20, 2021

@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 given templatepack.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 to templates folder. But I’d better keep the folders structure as what is in documentation.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found