Scaffolding: Running aspnet-codegenerator I get: MvcControllerWithContext.cshtml no found.

Created on 9 Aug 2020  Â·  27Comments  Â·  Source: dotnet/Scaffolding

Steps to reproduce:

Following the MVC Net Core tutorial until this point. Install locally dotnet-ef and dotnet-aspnet-codegenerator and the following packages.

Steps later in the tutorial, run this: export PATH=$HOME/.dotnet/tools:$PATH, and this(my case):

dotnet aspnet-codegenerator controller -name SessionController -m Session -dc ApplicationDbContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries

Expected behavior:

Generate SessionControllers and Views.

Actual behavior:

I get this error:

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: 'Session'
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:07.88

EDIT:

I installed dotnet-ef and dotnet-aspnet-codegenerator globally, but I get the same error. I notice that I have configured this var: NUGET_PACKAGES=/home/dlag/.config/nuget/packages. In that path, I have the error file:
packages/microsoft.visualstudio.web.codegenerators.mvc/3.1.2/Templates/ControllerGenerator/MvcControllerWithContext.cshtml
I try coping .config/nuget to .nuget but same error.
How can I tell dotnet to look for this path?

Additional information about the project being scaffolded, such as:

System:

5.7.12-arch1-1

Target framework(s):

dotnet 3.1.106
Microsoft.EntityFrameworkCore.Tools 3.1.6

Package version of Microsoft.VisualStudio.Web.CodeGeneration.Design - this may be added to your project by scaffolding:

3.1.4

Most helpful comment

Solution commands
On project folder execute

mkdir Templates && mkdir Templates/ControllerGenerator && mkdir Templates/ViewGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ControllerGenerator/* ./Templates/ControllerGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ViewGenerator/* ./Templates/ViewGenerator/

All 27 comments

Hello dlagg,
I found the way how to solve this. Please downgrade your version from v3.1.4 to v3.1.0 by using these commands:

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

I'm looking into it.

@luanpham107 solution works but this should not be necessary. can this not be fixed in current version?

Hello. I have the same problem, but when I run the commands suggested by @luanpham107 i get a new error:
No code generators found with the name 'controller'
When i type:
dotnet aspnet-codegenerator --help

It says:
No code generators are available in this project. Please add the 'Microsoft.VisualStudio.Web.CodeGeneration.Design' NuGet package to the project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.
But I have already added that package to my project.

Hello. I have the same problem, but when I run the commands suggested by @luanpham107 i get a new error:
No code generators found with the name 'controller'
When i type:
dotnet aspnet-codegenerator --help

It says:
No code generators are available in this project. Please add the 'Microsoft.VisualStudio.Web.CodeGeneration.Design' NuGet package to the project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.
But I have already added that package to my project.

I didn't try to downgrade, but maybe V.3.1.0 has different command syntax. Anycase downgrade shouldn't be the solution.

Same exact problem .. tried the early 3.1.0 version but I got the same error from @dlagg ... even the 3.1.3 does not work ...

I am experiencing the same issue on Ubuntu with dotnet 5 preview 8 installed from snap.

I get the same error after upgrading to dotnet 5 rc 1.

dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.100-rc.1.20452.10
Commit: 473d1b592e

Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /snap/dotnet-sdk/100/sdk/5.0.100-rc.1.20452.10/

Host (useful for support):
Version: 5.0.0-rc.1.20451.14
Commit: 38017c3935

.NET SDKs installed:
5.0.100-rc.1.20452.10 [/snap/dotnet-sdk/100/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [/snap/dotnet-sdk/100/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [/snap/dotnet-sdk/100/shared/Microsoft.NETCore.App]

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

dotnet tool list -g

Package Id Version Commands

dotnet-aspnet-codegenerator 5.0.0-rc.1.20453.2 dotnet-aspnet-codegenerator
dotnet-ef 5.0.0-rc.1.20451.13 dotnet-ef
dotnet-runtimeinfo 1.0.2 dotnet-runtimeinfo

so .. from issue #19418 (closed) I am told that the dotnet-aspnet-codegenerator has issues with Linux .. so looks like
the issue got carried along with the higher version as well

For me on Ubuntu 20.04 LTS the workaround yields this issue:
https://github.com/dotnet/Scaffolding/issues/1347
which is closed because it was fixed in 3.1.4.
I hope that 3.1.4 will be fixed so this will simply work on Linux?

Expecting the same issue with different versions of .net core sdk on Ubuntu. Tried downgrade aspnet-codegenerator and packages, didn't help.

Me too, I can't do nothing

Expecting the same issue with different versions of .net core sdk on Ubuntu. Tried downgrade aspnet-codegenerator and packages, didn't help.

Same here unfortunatly, looks like Ubuntu users have to manally go about scalfholding for now. Even the help doesn't really output as expected but gives No code generator found with the name 'controller'..

root ➜ /workspaces/dotnet-bootstrap-showcase/Showcase (user-mvc ✗) $ dotnet aspnet-codegenerator controller -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               

Selected Code Generator: controller
No code generator found with the name 'controller'.

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

RunTime 00:00:01.21

My project's csproj file:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
  </ItemGroup>

</Project>

i have same issue
i used visual studio 2019 for mac
and i update Microsoft.VisualStudio.Web.CodeGeneration.Design to 3.1.4
but i stell have same error
No code generators found with the name 'controller'


netcoreapp3.1
aspnet-test01-0141B016-EF1D-47F8-8149-CD1FEB854A2C












Screen Shot 2563-11-20 at 1 36 22 AM

i th

i have same issue
i used visual studio 2019 for mac
and i update Microsoft.VisualStudio.Web.CodeGeneration.Design to 3.1.4
but i stell have same error
No code generators found with the name 'controller'

netcoreapp3.1 aspnet-test01-0141B016-EF1D-47F8-8149-CD1FEB854A2C
Screen Shot 2563-11-20 at 1 36 22 AM

i think this issue fixed in net 5 :)

Same issue in .NET 5 (Ubuntu 20.04)

~/MvcMovie$ 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.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:06.16

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

Solution commands
On project folder execute

mkdir Templates && mkdir Templates/ControllerGenerator && mkdir Templates/ViewGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ControllerGenerator/* ./Templates/ControllerGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ViewGenerator/* ./Templates/ViewGenerator/

Hello dlagg,
I found the way how to solve this. Please downgrade your version from v3.1.4 to v3.1.0 by using these commands:

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

dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design -v 3.1.0

For direct package manipulation

Same problem here on Ubuntu 20.04 and dotnet 5.0.1

The workaround suggested by @ErikSmart and @LeandroRezendeCoutinho works!

Hello dlagg,
I found the way how to solve this. Please downgrade your version from v3.1.4 to v3.1.0 by using these commands:

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

dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design -v 3.1.0

For direct package manipulation

My project uses 3.1.0 and i have the same issue still.
@ErikSmart workaround worked.

Solution commands
On project folder execute

mkdir Templates && mkdir Templates/ControllerGenerator && mkdir Templates/ViewGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ControllerGenerator/* ./Templates/ControllerGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ViewGenerator/* ./Templates/ViewGenerator/

Thank you! I've put that into a script that I can execute before I do the scaffolding when developing in Ubuntu. It's a shame this has been broken since 3.1.4 and not fixed yet under Linux. I don't get this same error under Windows. I wonder if MacOS users are seeing the same issue or is it just limited to Linux users?

It seems to work on mac os. I'm currently working on fixing this. Sorry I haven't been able to allocate time for this but getting the linux version working is one of my top priorities rn.

I'll keep you guys updated.

It seems to work on mac os. I'm currently working on fixing this. Sorry I haven't been able to allocate time for this but getting the linux version working is one of my top priorities rn.

I'll keep you guys updated.

That's great news. Understand about being busy. Thanks for letting us know!

There seems to be an issue with the .nuget cache folder ( /home/username/.nuget in Linux ) if it resides in a Case Sensitive filesystem (Linux and Mac).
A way to temporarily avoid this problem seems to be mounting that folder in a Case Insensitive filesystem like it's explained in a similar Issue: https://github.com/dotnet/Scaffolding/issues/1393#issuecomment-752041418

Solution commands
On project folder execute

mkdir Templates && mkdir Templates/ControllerGenerator && mkdir Templates/ViewGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ControllerGenerator/* ./Templates/ControllerGenerator

cp -r /home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates/ViewGenerator/* ./Templates/ViewGenerator/

I have tried this but it doesn't work, still report can't find file. Besides, my loosing file named "Create.cs", not "MvcControllerWithContext.cshtml", so I guess there is other templates needed but I didn't put it in my project folder. I copy whole Templates folder in my project folder, this time it still report error, but different to past one. According to log, I found that if two identity templates copied to project folder but dont use them will cause a mistake, so I removed identity folder andIdentity_Versioned folder then retried, it works.

For mac users, and targeting net5.0 try this stack overflow answer:

https://stackoverflow.com/questions/63584060/aspnet-codegenerator-no-code-generators-available-even-after-adding-microsoft


  1. update global tools:
  dotnet tool install --global dotnet-aspnet-codegenerator
  dotnet tool update --global dotnet-aspnet-codegenerator
  dotnet tool install --global dotnet-ef
  dotnet tool update --global dotnet-ef
  1. add/update links to packages
  dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.EntityFrameworkCore.Design
  1. Replace string netcoreapp3.1.4 to net5.0 in .csproj and launch.json files
  2. Clear directories

    • bin

    • obj

  3. Rebuild project
  4. Finally run:
  dotnet aspnet-codegenerator --help

If all fine it will show available generators.

Was this page helpful?
0 / 5 - 0 ratings