Scaffolding: aspnet-codegenerator fails to create an API with actions on Ubuntu

Created on 15 Jul 2017  路  20Comments  路  Source: dotnet/Scaffolding

steps to reproduce

  1. dotnet new webapi -o WebApi

  2. change WebApi.csproj to be:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />

    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" />
     <PackageReference Include="Microsoft.Composition" Version="1.0.31" ExcludeAssets="All" />
      <PackageReference Include="System.Composition" Version="1.0.31" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
  </ItemGroup>
</Project>
  1. dotnet restore

  2. dotnet aspnet-codegenerator controller -name NotGonnaUseController -api -actions -outDir Controllers

Command Line: controller -name NotGonnaUseController -api -actions -outDir Controllers
Microsoft (R) Build Engine version 15.3.388.41745 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Building project ...
Microsoft (R) Build Engine version 15.3.388.41745 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  WebApi -> /home/badersur/Coding/MVA/ASP.NETCore-p1/WebApi/bin/Debug/netcoreapp1.1/WebApi.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.92
Command Line: --no-dispatch --port-number 52613 controller -name NotGonnaUseController -api -actions -outDir Controllers --dispatcher-version 1.0.1-rtm
Finding the generator 'controller'...
Running the generator 'controller'...
A file matching the name ApiControllerWithActions.cshtml was not found within any of the folders: /home/badersur/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/1.1.1/Templates/ControllerGenerator;/home/badersur/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/1.1.1/Templates/ViewGenerator
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
RunTime 00:00:06.69
  1. ls -l /home/badersur/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/1.1.1/Templates/ControllerGenerator
total 36
-rwxrw-rw- 1 badersur badersur  1375 Apr 28 01:36 ApiControllerWIthActions.cshtml
-rwxrw-rw- 1 badersur badersur  5074 Apr 28 01:36 ApiControllerWithContext.cshtml
-rwxrw-rw- 1 badersur badersur   614 Apr 28 01:36 ApiEmptyController.cshtml
-rwxrw-rw- 1 badersur badersur  2371 Apr 28 01:36 ControllerWithActions.cshtml
-rwxrw-rw- 1 badersur badersur   407 Apr 28 01:36 EmptyController.cshtml
-rwxrw-rw- 1 badersur badersur 10218 Apr 28 01:36 MvcControllerWithContext.cshtml

It seems like the issue is because ApiControllerWithActions.cshtml is named ApiControllerWIthActions.cshtml by mistake!

dotnet --info

.NET Command Line Tools (1.1.0-preview1-005051)

Product Information:
 Version:            1.1.0-preview1-005051
 Commit SHA-1 hash:  5e88564e56

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  17.04
 OS Platform: Linux
 RID:         ubuntu.16.10-x64
 Base Path:   /usr/share/dotnet/sdk/1.1.0-preview1-005051

Most helpful comment

I have the solution for UBUNTU valid for net core 3.0 , 3.1 and 5.0.

27/NOVEMBER/2020

ControllerGenerator contains de file MvcControllerWithContext.cshtml

You just have to copy the Template folders Template/ControllerGenerator and Templete/ViewGenerator to own project.

This is the path of the missing files: /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates

All 20 comments

Still a problem with Dotnet core 3.1.301
the output of dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.1.302
 Commit:    41faccf259

Runtime Environment:
 OS Name:     zorin
 OS Version:  15
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.302/

Host (useful for support):
  Version: 3.1.6
  Commit:  3acd9b0cd1

.NET Core SDKs installed:
  3.1.302 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

output of dotnet aspnet-codegenerator controller -name ServerController -async -api -m Server -dc ServerContext -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: 'Server'
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.48

output of ls -l ~/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/3.1.4/Templates/ControllerGenerator/

total 36
-rwxrw-r-- 1 jared jared  1293 Aug  3 18:28 ApiControllerWithActions.cshtml
-rwxrw-r-- 1 jared jared  4901 Aug  3 18:28 ApiControllerWithContext.cshtml
-rwxrw-r-- 1 jared jared   411 Aug  3 18:28 ApiEmptyController.cshtml
-rwxrw-r-- 1 jared jared  2389 Aug  3 18:28 ControllerWithActions.cshtml
-rwxrw-r-- 1 jared jared   407 Aug  3 18:28 EmptyController.cshtml
-rwxrw-r-- 1 jared jared 10197 Aug  3 18:28 MvcControllerWithContext.cshtml

Still a problem with Dotnet core 3.1.301
the output of dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.1.302
 Commit:    41faccf259

Runtime Environment:
 OS Name:     zorin
 OS Version:  15
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.302/

Host (useful for support):
  Version: 3.1.6
  Commit:  3acd9b0cd1

.NET Core SDKs installed:
  3.1.302 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

output of dotnet aspnet-codegenerator controller -name ServerController -async -api -m Server -dc ServerContext -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: 'Server'
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.48

output of ls -l ~/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/3.1.4/Templates/ControllerGenerator/

total 36
-rwxrw-r-- 1 jared jared  1293 Aug  3 18:28 ApiControllerWithActions.cshtml
-rwxrw-r-- 1 jared jared  4901 Aug  3 18:28 ApiControllerWithContext.cshtml
-rwxrw-r-- 1 jared jared   411 Aug  3 18:28 ApiEmptyController.cshtml
-rwxrw-r-- 1 jared jared  2389 Aug  3 18:28 ControllerWithActions.cshtml
-rwxrw-r-- 1 jared jared   407 Aug  3 18:28 EmptyController.cshtml
-rwxrw-r-- 1 jared jared 10197 Aug  3 18:28 MvcControllerWithContext.cshtml

Are you already solve this problem? I've some issue

nope still trying to figure it out. any ideas?

.NET Core SDK (reflecting any global.json):
 Version:   3.1.302
 Commit:    41faccf259

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  18.04
 OS Platform: Linux
 RID:         ubuntu.18.04-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.302/

Host (useful for support):
  Version: 3.1.6
  Commit:  3acd9b0cd1

.NET Core SDKs installed:
  3.1.302 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Building from the First MVC APP. During controller scaffolding:

dotnet aspnet-codegenerator controller -name MoviesController -m Movie -dc MvcMovieContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries

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: 'Movie'
A file matching the name MvcControllerWithContext.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:05.63

I have messed with the dependencies that exist in MvcMovie.csproj, swapping versions in and out.

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SQLite" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
  </ItemGroup>

</Project>

No joy.

I ran into the same problem following the MVC tutorial over at the Official Microsoft Documentation. Did you find a fix? I tried downgrading the dotnet-aspnet-codegenerator to 3.1.0 but that didn't work.

Awesome, good! I thought I'm the only dummy who can't follow simple tutorial. This official tutorial does not work with containers at all.

I was working on docker integration for a few days last week.

https://gitlab.com/whittington.andy/dotnet-api

The readme.md might help someone work through it.

The only fix for the dotnet-aspnet-codegenerator that I currently have been able to successfully use is to downgrade the tool. If that doesn't work, what error do you get after?

@whittingtonandy downgrading to any 3.x version below 3.1.4 gives me "No code generators found with the name 'controller'" instead

same

@whittingtonandy workaround worked for me. Using docker image mcr.microsoft.com/dotnet/core/sdk:3.1

dotnet tool uninstall --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.0

@pi3ch Downgrading from 3.1.4 to 3.1.3 worked for me. I guess this is some issue with the latest release of the package.

Just to update your workaround:

dotnet tool uninstall --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3

has anyone solved this issue?
downgrading doesn't work for me (debian)

@kresimirfijacko the issue is being tracked here

This problems is similar occurred when I do official tutorial on https://docs.microsoft.com/pt-br/aspnet/core/tutorials/razor-pages/model?view=aspnetcore-5.0&tabs=visual-studio-code when executed of command:
dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages/Movies --referenceScriptLibraries

This error occurred:
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Movie'
A file matching the name Create.cshtml was not found within any of the folders:
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.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:08.02

Information of my computer:
**.NET information
Version: 5.0.0
FrameworkDescription: .NET 5.0.0
Libraries version: 5.0.0
Libraries hash: cf258a14b70ad9069470a108f13765e0e5988f51

**Environment information
OSDescription: Linux 5.8.18-200.fc32.x86_64 #1 SMP Mon Nov 2 19:49:11 UTC 2020
OSVersion: Unix 5.8.18.200
OSArchitecture: X64
ProcessorCount: 8

Ubuntu 20.04 have same problem.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'AuthEmail' A file matching the name Create.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:05.94

Oh, No. Manjaro 20.2 rc3 have same problem too!
A file matching the name MvcControllerWithContext.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)

I have the solution for UBUNTU valid for net core 3.0 , 3.1 and 5.0.

27/NOVEMBER/2020

ControllerGenerator contains de file MvcControllerWithContext.cshtml

You just have to copy the Template folders Template/ControllerGenerator and Templete/ViewGenerator to own project.

This is the path of the missing files: /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates

I have the solution for UBUNTU valid for net core 3.0 , 3.1 and 5.0.

27/NOVEMBER/2020

ControllerGenerator contains de file MvcControllerWithContext.cshtml

You just have to copy the Template folders Template/ControllerGenerator and Templete/ViewGenerator to own project.

This is the path of the missing files: /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates

This worked for me, thanks

SDK de .NET (que refleje cualquier global.json):
 Version:   5.0.100
 Commit:    5044b93829

Entorno de tiempo de ejecuci贸n:
 OS Name:     manjaro
 OS Version:  
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.100/

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  5.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download 

I have the solution for UBUNTU valid for net core 3.0 , 3.1 and 5.0.

27/NOVEMBER/2020

ControllerGenerator contains de file MvcControllerWithContext.cshtml

You just have to copy the Template folders Template/ControllerGenerator and Templete/ViewGenerator to own project.

This is the path of the missing files: /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates

Where specifically in the project should the files (or whole folders) be copied to?

EDIT:
I made a "Templates" Folder at the root of my application and copied the "ControllerGenerator" and "ViewGenerator" folders and that worked.

Thanks @ErikSmart !!!!

Tenho a solu莽茫o para UBUNTU v谩lida para net core 3.0, 3.1 e 5.0.

27 / NOVEMBRO / 2020

ControllerGenerator cont茅m o arquivo MvcControllerWithContext.cshtml

Voc锚 apenas tem que copiar as pastas Template Template / ControllerGenerator e Templete / ViewGenerator para o pr贸prio projeto.

Este 茅 o caminho dos arquivos ausentes: /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates

Utilizo ElementaryOS. Fiz como o @RkNjeru disse no EDIT e funcionou perfeitamente.
Obrigado <3

Was this page helpful?
0 / 5 - 0 ratings