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

Unable to install template from nuget #2763

Closed fbarresi closed 3 years ago

fbarresi commented 3 years ago

Hello!

I'm trying to install a custom template for a whole solution I worte and published in nuget without any success. I can install the template from source and I also tested it works right in this way. repository: https://github.com/fbarresi/twincat-wpf-boilerplate nuget package: https://www.nuget.org/packages/TwincatWpfHMI.template/1.0.5

Steps to reproduce

I run dotnet new --install TwincatWpfHMI.template::1.0.5

Expected behavior

The template should be installed and listed.

Actual behavior

The template is not listed and there is no error message.

Environment data

Output of dotnet --info

.NET SDK (gemäß "global.json"):
 Version:   5.0.102
 Commit:    71365b4d42

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.102\

Host (useful for support):
  Version: 5.0.2
  Commit:  cb5f173b96

.NET SDKs installed:
  3.1.403 [C:\Program Files\dotnet\sdk]
  3.1.405 [C:\Program Files\dotnet\sdk]
  5.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
DavidKarlas commented 3 years ago

Seems to be working for me just fine: image and created: image

Can you execute dotnet new -u that should list all installed things.

I wonder if problem is that its conflicting with folder installation of same template you have on your machine...

fbarresi commented 3 years ago

Hi! Thank you for your quick reply. I still cannot install the template, so I suppose this behavior may depend on my machine, but what causes it and why?

That's the output of dotnet new -u

PS C:\> dotnet new -u
Template Instantiation Commands for .NET Core CLI

Currently installed items:
  Microsoft.DotNet.Common.ProjectTemplates.3.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Common.ProjectTemplates.3.1
      Version: 3.1.11
      Author: Microsoft
    Templates:
      Class library (classlib) C#
      Class library (classlib) F#
      Class library (classlib) VB
      Console Application (console) C#
      Console Application (console) F#
      Console Application (console) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Common.ProjectTemplates.3.1

  Microsoft.DotNet.Common.ProjectTemplates.2.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Common.ProjectTemplates.2.1
      Version: 1.0.2-beta3
      Author: Microsoft
    Templates:
      Class library (classlib) C#
      Class library (classlib) F#
      Class library (classlib) VB
      Console Application (console) C#
      Console Application (console) F#
      Console Application (console) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Common.ProjectTemplates.2.1

  Microsoft.DotNet.Test.ProjectTemplates.2.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Test.ProjectTemplates.2.1
      Version: 1.0.2-beta4.20105.2
      Author: Microsoft
    Templates:
      Unit Test Project (mstest) C#
      Unit Test Project (mstest) F#
      Unit Test Project (mstest) VB
      xUnit Test Project (xunit) C#
      xUnit Test Project (xunit) F#
      xUnit Test Project (xunit) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Test.ProjectTemplates.2.1

  Microsoft.DotNet.Web.ProjectTemplates.3.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.ProjectTemplates.3.1
      Version: 3.1.11
      Author: Microsoft
    Templates:
      Blazor Server App (blazorserver) C#
      ASP.NET Core Empty (web) C#
      ASP.NET Core Empty (web) F#
      ASP.NET Core gRPC Service (grpc) C#
      Razor Class Library (razorclasslib) C#
      ASP.NET Core Web App (webapp) C#
      ASP.NET Core Web App (Model-View-Controller) (mvc) C#
      ASP.NET Core Web App (Model-View-Controller) (mvc) F#
      ASP.NET Core Web API (webapi) C#
      ASP.NET Core Web API (webapi) F#
      Worker Service (worker) C#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.ProjectTemplates.3.1

  Microsoft.DotNet.Web.ProjectTemplates.2.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.ProjectTemplates.2.1
      Version: 2.1.14
      Author: Microsoft
    Templates:
      ASP.NET Core Empty (web) C#
      ASP.NET Core Empty (web) F#
      Razor Class Library (razorclasslib) C#
      ASP.NET Core Web App (razor) C#
      ASP.NET Core Web App (Model-View-Controller) (mvc) C#
      ASP.NET Core Web App (Model-View-Controller) (mvc) F#
      ASP.NET Core Web API (webapi) C#
      ASP.NET Core Web API (webapi) F#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.ProjectTemplates.2.1

  Microsoft.DotNet.Web.Spa.ProjectTemplates.2.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.Spa.ProjectTemplates.2.1
      Version: 2.1.14
      Author: Microsoft
    Templates:
      ASP.NET Core with Angular (angular) C#
      ASP.NET Core with React.js (react) C#
      ASP.NET Core with React.js and Redux (reactredux) C#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.Spa.ProjectTemplates.2.1

  Microsoft.DotNet.Common.ItemTemplates
    Details:
      NuGetPackageId: Microsoft.DotNet.Common.ItemTemplates
      Version: 5.0.2
      Author: Microsoft
    Templates:
      dotnet gitignore file (gitignore)
      global.json file (globaljson)
      NuGet Config (nugetconfig)
      Solution File (sln)
      Dotnet local tool manifest file (tool-manifest)
      Web Config (webconfig)
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Common.ItemTemplates

  Microsoft.AspNetCore.Components.WebAssembly.Templates
    Details:
      NuGetPackageId: Microsoft.AspNetCore.Components.WebAssembly.Templates
      Version: 3.2.1
      Author: Microsoft
    Templates:
      Blazor WebAssembly App (blazorwasm) C#
    Uninstall Command:
      dotnet new -u Microsoft.AspNetCore.Components.WebAssembly.Templates

  Microsoft.DotNet.Common.ProjectTemplates.5.0
    Details:
      NuGetPackageId: Microsoft.DotNet.Common.ProjectTemplates.5.0
      Version: 5.0.2
      Author: Microsoft
    Templates:
      Class library (classlib) C#
      Class library (classlib) F#
      Class library (classlib) VB
      Console Application (console) C#
      Console Application (console) F#
      Console Application (console) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Common.ProjectTemplates.5.0

  Microsoft.DotNet.Test.ProjectTemplates.3.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Test.ProjectTemplates.3.1
      Version: 1.0.2-beta4.20176.1
      Author: Microsoft
    Templates:
      Unit Test Project (mstest) C#
      Unit Test Project (mstest) F#
      Unit Test Project (mstest) VB
      xUnit Test Project (xunit) C#
      xUnit Test Project (xunit) F#
      xUnit Test Project (xunit) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Test.ProjectTemplates.3.1

  Microsoft.DotNet.Web.ProjectTemplates.5.0
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.ProjectTemplates.5.0
      Version: 5.0.2
      Author: Microsoft
    Templates:
      Blazor Server App (blazorserver) C#
      Blazor WebAssembly App (blazorwasm) C#
      ASP.NET Core Empty (web) C#
      ASP.NET Core Empty (web) F#
      ASP.NET Core gRPC Service (grpc) C#
      Razor Class Library (razorclasslib) C#
      ASP.NET Core Web App (webapp) C#
      ASP.NET Core Web App (Model-View-Controller) (mvc) C#
      ASP.NET Core Web App (Model-View-Controller) (mvc) F#
      ASP.NET Core Web API (webapi) C#
      ASP.NET Core Web API (webapi) F#
      Worker Service (worker) C#
      Worker Service (worker) F#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.ProjectTemplates.5.0

  Microsoft.DotNet.Web.Spa.ProjectTemplates.3.1
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.Spa.ProjectTemplates.3.1
      Version: 3.1.11
      Author: Microsoft
    Templates:
      ASP.NET Core with Angular (angular) C#
      ASP.NET Core with React.js (react) C#
      ASP.NET Core with React.js and Redux (reactredux) C#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.Spa.ProjectTemplates.3.1

  Microsoft.DotNet.Wpf.ProjectTemplates
    Details:
      NuGetPackageId: Microsoft.DotNet.Wpf.ProjectTemplates
      Version: 5.0.2-servicing.20613.2
      Author: Microsoft
    Templates:
      WPF Application (wpf) C#
      WPF Application (wpf) VB
      WPF Class library (wpflib) C#
      WPF Class library (wpflib) VB
      WPF Custom Control Library (wpfcustomcontrollib) C#
      WPF Custom Control Library (wpfcustomcontrollib) VB
      WPF User Control Library (wpfusercontrollib) C#
      WPF User Control Library (wpfusercontrollib) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Wpf.ProjectTemplates

  NUnit3.DotNetNew.Template
    Details:
      NuGetPackageId: NUnit3.DotNetNew.Template
      Version: 1.8.1
      Author: akharlov
    Templates:
      NUnit 3 Test Project (nunit) C#
      NUnit 3 Test Item (nunit-test) C#
      NUnit 3 Test Project (nunit) F#
      NUnit 3 Test Item (nunit-test) F#
      NUnit 3 Test Project (nunit) VB
      NUnit 3 Test Item (nunit-test) VB
    Uninstall Command:
      dotnet new -u NUnit3.DotNetNew.Template

  Microsoft.DotNet.Test.ProjectTemplates.5.0
    Details:
      NuGetPackageId: Microsoft.DotNet.Test.ProjectTemplates.5.0
      Version: 1.0.2-beta4.20420.1
      Author: Microsoft
    Templates:
      Unit Test Project (mstest) C#
      Unit Test Project (mstest) F#
      Unit Test Project (mstest) VB
      xUnit Test Project (xunit) C#
      xUnit Test Project (xunit) F#
      xUnit Test Project (xunit) VB
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Test.ProjectTemplates.5.0

  Microsoft.DotNet.Web.ItemTemplates
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.ItemTemplates
      Version: 5.0.2
      Author: Microsoft
    Templates:
      Protocol Buffer File (proto)
      Razor Component (razorcomponent) C#
      Razor Page (page) C#
      MVC ViewImports (viewimports) C#
      MVC ViewStart (viewstart) C#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.ItemTemplates

  Microsoft.DotNet.Web.Spa.ProjectTemplates.5.0
    Details:
      NuGetPackageId: Microsoft.DotNet.Web.Spa.ProjectTemplates.5.0
      Version: 5.0.2
      Author: Microsoft
    Templates:
      ASP.NET Core with Angular (angular) C#
      ASP.NET Core with React.js (react) C#
      ASP.NET Core with React.js and Redux (reactredux) C#
    Uninstall Command:
      dotnet new -u Microsoft.DotNet.Web.Spa.ProjectTemplates.5.0

  Microsoft.Dotnet.WinForms.ProjectTemplates
    Details:
      NuGetPackageId: Microsoft.Dotnet.WinForms.ProjectTemplates
      Version: 5.0.2-servicing.20613.1
      Author: Microsoft
    Templates:
      Windows Forms App (winforms) C#
      Windows Forms App (winforms) VB
      Windows Forms Control Library (winformscontrollib) C#
      Windows Forms Control Library (winformscontrollib) VB
      Windows Forms Class Library (winformslib) C#
      Windows Forms Class library (winformslib) VB
    Uninstall Command:
      dotnet new -u Microsoft.Dotnet.WinForms.ProjectTemplates

PS C:\>
DavidKarlas commented 3 years ago

Hi, sorry for slow response.

I had to give some thought what is happening here, and it seems like our logging when install fails is very poor at this moment :(.

So if you are willing to try 2 things for me, I would appreciate...

  1. Create new temporary folder
  2. Create new file called, test.csproj
  3. Set content of that file to be

    <Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1</TargetFrameworks>
    </PropertyGroup>
    
    <ItemGroup>
    <PackageReference Remove="Microsoft.NETCore.App" />
    <PackageReference Include="TwincatWpfHMI.template" Version="1.0.5" />
    
    </ItemGroup>
    </Project>
  4. Execute dotnet restore test.csproj --packages Packages This should create new folder called Packages and I wonder if it contains TwincatWpfHMI.template.nupkg folder?

If that works... I would like you to try another thing... Can you Zip folder called C:\Users\David\.templateengine where you replace David with your user name, and then delete .templateengine and try installing again? Reason for Zipping this folder is... that If this works we can maybe try to figure out what this bug is about since it will be reproducible....

If all of this is too much work, its OK... In future version of TemplateEngine and dotnet new we plan to improve logging which should make diagnosing this easier.

fbarresi commented 3 years ago

Hi! No problem, I'm glad to help with those tests! 👍

At this point I think it makes sense to debug the dotnet new cli locally on my machine. Should I try?

DavidKarlas commented 3 years ago

Looks like problem is with dotnet restore test.csproj --packages Packages not working... That is why dotnet new fails to install...

Can you execute dotnet restore -v diag test.csproj --packages Packages and upload output to https://gist.github.com/ and share link here?

fbarresi commented 3 years ago

Here my output.

Can you understand it or should switch to English for cli output?

DavidKarlas commented 3 years ago

Can you execute echo %MSBuildSDKsPath%? Seems like you have it set and it is preventing dotnet restore from downloading .nupkg.

fbarresi commented 3 years ago

Yes, it is set:

C:\>echo %MSBuildSDKsPath%
C:\Program Files\dotnet\sdk\3.1.402\Sdks

C:\>

Should I delete this environment variable?

DavidKarlas commented 3 years ago

If you don't need it unset it. It should make installing templates work.

fbarresi commented 3 years ago

Thank you very much! it works!