Scaffolding: aspnet-codegenerator fails to create an API with actions on Ubuntu
steps to reproduce
-
dotnet new webapi -o WebApi -
change
WebApi.csprojto 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>
-
dotnet restore -
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
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20
Commits related to this issue
- Rename ApiControllerWIthActions.cshtml to ApiControllerWithActions.cshtml fixes #559 — committed to badersur/Scaffolding by badersur 7 years ago
- Re apply fix for #559 — committed to dotnet/Scaffolding by prafullbhosale 7 years ago
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@whittingtonandy downgrading to any 3.x version below 3.1.4 gives me “No code generators found with the name ‘controller’” instead
@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:
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.
@whittingtonandy workaround worked for me. Using docker image
mcr.microsoft.com/dotnet/core/sdk:3.1Awesome, good! I thought I’m the only dummy who can’t follow simple tutorial. This official tutorial does not work with containers at all.
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 !!!
same
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?