dotnet aspnet-codegenerator not able to generate any templates in WSL dotnet CLI
See original GitHub issueIssue moved from dotnet/sdk#14546
- Please respond to @DJBrunelle.
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:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
@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.
@dkja How did you solve this issue? 😃