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 aspnet-codegenerator not able to generate any templates in WSL dotnet CLI

See original GitHub issue

Issue moved from dotnet/sdk#14546


From @DJBrunelle on Saturday, November 14, 2020 9:00:11 PM

I’m currently learning how to use the dotnet CLI in WSL 2 (Ubuntu 20) for building web API’s. I’m attempting to use the scaffolding tool aspnet-codegenerator, but it can’t find any templates to generate from. I’ve gone through many forums and have made sure to add the Microsoft.VisualStudio.Web.CodeGeneration.Design and other packages, made sure the aspnet-codegenerator tool was installed globally, and provided the csproj file path to the tool. Nothing seems to have changed the output of the basic dotnet aspnet-codegenerator -h command.

I’m using ASP.NET core version 5, and I’m trying to generate scaffolds inside a new project generated from the command dotnet new webapi

apitest.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" NoWarn="NU1605" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
  </ItemGroup>

</Project>

Here is the output when I try to run the tool:

~/code/testing/apitest -> dotnet aspnet-codegenerator -h


Usage: aspnet-codegenerator [arguments] [options]

Arguments:
  generator  Name of the generator. Check available generators below.

Options:
  -p|--project             Path to .csproj file in the project.
  -n|--nuget-package-dir   
  -c|--configuration       Configuration for the project (Possible values: Debug/ Release)
  -tfm|--target-framework  Target Framework to use. (Short folder name of the tfm. eg. net46)
  -b|--build-base-path     
  --no-build               

No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.

RunTime 00:00:01.02

Using this tutorial, I get the following output:

~/code/testing/apitest -> dotnet aspnet-codegenerator controller -name TodoItemsController -async -api -m TodoItem -dc TodoContext -outDir Controllers
Building project ...
Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'TodoItem'
A file matching the name ApiControllerWithContext.cshtml was not found within any of the folders: 
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:04.68

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dkjacommented, Dec 29, 2020

@jungho I rebuilt Scaffolding tool with fix.

In file: src/VS.Web.CG.Msbuild/ProjectContextWriter.cs, DeserializePackages() returns dependencies paths.

The paths are eg. ~/.nuget/packages/Microsoft.AspNetCore.Identity.UI, but (probably only on linux) directories are named lower case (microsoft.aspnetcore.identity.ui instead Microsoft.AspNetCore.Identity.UI).

Tool checks does directory exist and returns… (wtf?) empty string if doesn’t. So scaffonding cannot find dependencies.

3reactions
junghocommented, Dec 23, 2020

@dkja How did you solve this issue? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet aspnet-codegenerator not able to generate any ...
I'm attempting to use the scaffolding tool aspnet-codegenerator, but it can't find any templates to generate from. I've gone through many forums ...
Read more >
dotnet aspnet-codegenerator command
The dotnet aspnet-codegenerator global command runs the ASP.NET Core code generator and scaffolding engine. Arguments. generator. The code ...
Read more >
c# - aspnet-codegenerator could not execute
Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET Core program, but dotnet-aspnet- ......
Read more >
Visual Studio Code error - 'dotnet' is not recognized as an ...
If you close VSCode after closing the terminal, the problem will be fixed. But you need to make sure .net is installed. If...
Read more >
Cannot Scaffold API Controller OSX (Big Sur) Visual Studio ...
If I create a standard DOTNET Core 3.1 Empty WEBAPI. Add new scaffolding; Select API Controller empty; Enter Controller Name: It succeeds, and ......
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