Scaffolding: A file matching the name ApiControllerWithContext.cshtml was not found within any of the folders:

Note: If filing an issue related to using Scaffolding within Microsoft Visual Studio, please file an issue on the Microsoft Developer Community instead of here. This can be accomplished from Visual Studio by clicking on Help > Send Feedback, and choosing the appropriate action.

Steps to reproduce:

dotnet aspnet-codegenerator controller -name TodoItemsController -async -api -m TodoItem -dc TodoContext -outDir Controllers

Expected behavior:

Should run without any errors

Actual behavior:

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:06.25

Additional information about the project being scaffolded, such as:

I am using vs code in Ubuntu 18.04

Target framework(s):

dotnet core 3.1

Package version of Microsoft.AspNetCore.App or Microsoft.AspNetCore.All (if applicable):

3.1

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 38 (4 by maintainers)

Most upvoted comments

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 had the same problem. The version is dotnet-sdk-3.1 is 3.1.401-1 aspnet-codegenerator is 3.1.4. I tried Downgraded each to 3.1.302-1 and 3.1.3. Then it worked. With only one downgrade, it didn’t work. My environment is Linux Mint 19.3.

can you share step for downgrade?

sudo apt-get remove dotnet-sdk-3.1 --purge sudo apt-get install dotnet-sdk-3.1=3.1.302-1 sudo apt-mark hold dotnet-sdk-3.1 dotnet tool uninstall -g dotnet-aspnet-codegenerator dotnet tool install -g dotnet-aspnet-codegenerator --version 3.1.3

https://github.com/dotnet/Scaffolding/issues/559#issuecomment-670198811

Ran into this yesterday. Downgraded the tool with an dotnet tool uninstall command. The older version works correctly.

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

Messing with package versions inside the project .csproj made little difference.

I was coming from the tutorials at Microsoft. This breaks the razor and MVC tutorials.

I was actually able to move past the error and complete the tutorial with the above command. That was the intended goal.


Update:

@telmotrooper Got the tool to work here?! With this:

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

Obviously blowing out a couple versions may have been a bit heavy handed.

Others like @GillesWHC didn’t fare so well and ended up with “No code generators”.

To those of you that got that error your not alone!


@undmeer has the downgrade process for system level installs. That may be more right than blasting the tool with a global uninstall and assuming everything is ok.


@cezarlamann might have a good idea about where to start looking for the solution on linux platforms.

@Rick-Anderson you mean the downgrading part? I tried that, but the tool gave me No code generators found with the name 'controller' when running 3.1.0.

Hey all, @robineero @rinfz @luizhp @chadmwest @psmatsinhe @akchhayalok @en1tan @LeandroRezendeCoutinho @YukiCoco @whittingtonandy @gillescoolen @Jaredes0514 @ducbm95 @luisquintanilla @fuadnafiz98 @agnelovaz @RKiemGames @fuadnafiz98

I have a fix for this issue out with a new 3.1.5 and 5.0.2 package out. Use dotnet tool update dotnet-aspnet-codegenerator -g --version 3.1.5/5.0.2 depending on if you are targeting .netcoreapp3.1 or net5.0. I would like it if someone could confirm the fix before I close the issue.

You will also need to update the Microsoft.VisualStudio.Web.CodeGeneration.Design package as well.

Apologize for the lengthy delay on this fix and appreciate all the feedback.

Pay attention to the version. If updated to 5.0.1 use => .codegenerators.mvc/5.0.1/

Same problem with 3.1.4. When I downgrate to version 3.1.0, the new problem found: No code generators found with the name ‘controller’

Here are the steps I took:

  1. Check the target version.
sudo apt show -a dotnet-sdk-3.1 | more
  1. Assign priorities.
sudo echo "Package: dotnet-sdk-3.1
Pin: version 3.1.302-1
Pin-Priority: 1000" > /etc/apt/preferences.d/microsoft-prod.pref
  1. Then install it. Older versions will be deleted automatically.
sudo apt install dotnet-sdk-3.1
  1. And codegenerator.
dotnet tool uninstall -g dotnet-aspnet-codegenerator
dotnet tool install -g dotnet-aspnet-codegenerator --version 3.1.3

Please see the following link for PRIORITY apt_preferences(5) Debian Manpages

dotnet-sdk doesn’t seem to have any dependent packages, but considering the dependencies, I like this method.

I had the same problem. The version is dotnet-sdk-3.1 is 3.1.401-1 aspnet-codegenerator is 3.1.4.

I tried Downgraded each to 3.1.302-1 and 3.1.3. Then it worked. With only one downgrade, it didn’t work.

My environment is Linux Mint 19.3.

I could solve this by doing a tricky patch.

I was working around this tutorial and ended with this. So I tried to downgrade the scaffolding engine tool to versions 1.3.0 and 1.3.3, and even installed the dotnet-ef tool. But that only led to the another known issue: No code generators found with the name 'controller.

I find out that this issue seems often happening to users which uses the .NET SDK CLI rather than those who uses the IDE, Visual Studio. So I had the hypothesis that the ApiControllerWithContext.cshtml was supposed to be a local resource into the project’s source code. Such resource the IDE may satisfy, but the CLI cannnot by itself.

I googled a few and found how the template code is implemented in a BitBucket’s repository, BuildScripts committed by Vince Seely in 2018. I don’t know if it’sthe official template used, but it is currently working for me.

api-controller-generator-by-vince.zip

I also found another implementation of the code by @rewards510 in GitHub Gist. But this one has some “enhacements” by making use of DTOs and IRepository custom implementations for the target data model. It has functionalities out of the tutorial’s actual requirements, but it may be helpful to your case.

api-controller-generator-snippet-by-rewards510.zip

What I did was copy and paste the first implementation I metioned into a file ApiControllerWithContext.cshtml at the Templates\ControllerGenerator folder from the project’s root folder (as @rewards510 recommends.)

Finally I ran the tool and it worked! (And also, it compiled and let me finish the tutorial.)

I did that using the .NET SDK at version 3.1.402 installed from APT, the dotnet-aspnet-codegenerator tool at version 3.1.4 (which originally produces this issue), and the dotnet-ef at version 3.1.8 (which may be irrevelant). All that on Xubuntu LTS 20.04 with recent updates at the date.

I’m not sure if this actually solve the problem. I think the SDK or tools should be able to satisfy every template by themselves, though. However, it was a good discovering. Now I know that templates can be customized!

Hi @akchhayalok I believe that it’s incorrect to close this issue as it’s still present in the latest versions dotnet-sdk-3.1 version 3.1.401-1 and aspnet-codegenerator version 3.1.4. @undmeer just suggested a version downgrade to avoid the bug in the latest versions, but the bug is still there.

As a new user of asp.net and trying the MS tutorial this bug was driving me crazy, glad I found the world around.

Could this issues be referenced in the tutorial?

Same problem with the same error message using the mcr.microsoft.com/dotnet/core/sdk Docker image on Windows 10 2004 with version 3.1.4.

I’ve tried both the 3.1.401-buster (aka latest) tag (Debian 10) and the 3.1.401-focal tag (Ubuntu 20.04). Downgrading does not solve the issue and produces a different error message for each version between 3.1.0 and 3.1.4, including the message OP posted for 3.1.4.