Scaffolding: Microsoft.VisualStudio.Web.CodeGeneration.Design package not being found by the dotnet aspnet-codegenerator tool

I just created an MVC app with dotnet new mvc --name test-project (netcoreapp3.1), without any kind of database access and Identity, which I would like to add by hand for customisation purposes. Then I added some packages in order to use the dotnet aspnet-codegenerator tool. My .csproj looks like this:

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

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

  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.7" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.7" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.7">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.7">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
  </ItemGroup>
</Project>

As you can see, the Microsoft.VisualStudio.Web.CodeGeneration.Design is the first in the list. However, when I try to run any scaffolder from the dotnet aspnet-codegenerator tool (e.g.: dotnet aspnet-codegenerator identity -h), I get the following message:

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

Even if I specify the .csproj file with the -p flag, I still get the same message. While doing some research, I found this Issue in the repo, but it’s a different thing: the OP was trying to add the scaffolder to a .NET Core App 3.0 using the 3.1 scaffolder version.

I’m using dotnet 3.1.401 on Xubuntu 20.04.

Any thoughts? Thank you in advance.

Steps to reproduce:

  • Install latest dotnet through MS repos
  • dotnet tool install dotnet-aspnet-codegenerator --version 3.1.4
  • dotnet new mvc
  • dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design -v 3.1.4 && dotnet restore && dotnet build
  • dotnet aspnet-codegenerator identity -h

Expected behaviour:

  • The Scaffolding tool should at least show any helpful information about the scaffolder

Actual behaviour:

  • It shows the following message, even after adding the referred NuGet Package to the project: No code generators are available in this project. Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet package reference.

Additional information about the project being scaffolded, such as:

Target framework(s): netcoreapp3.1

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

Package version of Microsoft.VisualStudio.Web.CodeGeneration.Design - this may be added to your project by scaffolding: 3.1.4, actually this problem can be reproduced even with the 3.1.3 version of it.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 17
  • Comments: 57 (9 by maintainers)

Most upvoted comments

Since @mwdmwd was able to find the root cause for the problem, I was successful with the following workaround (using Ubuntu 18.04 and .NET 5.0):

Create a dummy vfat filesystem:

dd if=/dev/zero of=/tmp/mynuget bs=1024k count=2000
mkfs.vfat /tmp/mynuget

Mount it in place of your nuget directory:

sudo mount -o uid=myuser,gid=myuser -t vfat /tmp/mynuget /home/myuser/.nuget

Then, after running dotnet restore the scaffolding works as expected.

In Pop OS 20.04 I solved this with sdk and aspnet-codegenerator downgrade sudo apt install dotnet-sdk-3.1=3.1.301-1 dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3 This is my dotnet --info `SDK de .NET Core (reflejando cualquier global.json): Version: 3.1.301 Commit: 7feb845744

Entorno de tiempo de ejecución: OS Name: pop OS Version: 20.04 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/3.1.301/

Host (useful for support): Version: 3.1.8 Commit: 9c1330dedd

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

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

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

Hey all, @rhaynes123 @jonathan-daniel @cezarlamann @sanjitn @mtausig @MadeleineRoberts-WellSky @gustavohrgomes @stephen-innotek @lctx @iBolski @KilianKilmister @NorbiPeti

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.

The problem is that ProjectContextWriter creates package paths by combining a base directory (~/.nuget/packages), the package name, and the package version. The package name is written with Capitalized.Words, but the directories inside .nuget/packages are lowercase. This would work on a case-insensitive filesystem (and apparently it does work on Windows), but on a case-sensitive filesystem ProjectContextWriter sees that the path it just made doesn’t exist and puts an empty string in its place.

A quick workaround is to convert the package name to lower case before using it as a part of the path, but this is probably not the right way to fix this. (?)

Since @mwdmwd was able to find the root cause for the problem, I was successful with the following workaround (using Ubuntu 18.04 and .NET 5.0):

Create a dummy vfat filesystem:

dd if=/dev/zero of=/tmp/mynuget bs=1024k count=2000
mkfs.vfat /tmp/mynuget

Mount it in place of your nuget directory:

sudo mount -o uid=myuser,gid=myuser -t vfat /tmp/mynuget /home/myuser/.nuget

Then, after running dotnet restore the scaffolding works as expected.

Thank’s a lot! I stumbled (again) on this problem, and you just solved it 1 hour before I started looking if anyone did something new here 😄

Just for anyone informatuon, @mtausig solution work’s perfectly fine on Manjaro.

➜  App git:(auth) ✗ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.101
 Commit:    d05174dc5a

Runtime Environment:
 OS Name:     manjaro
 OS Version:  
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.101/

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

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

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

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

@edit

There is other issue though. Project just cannot compile in memory. I get a lot of issues with Razor pages overriding life-cycle methods…

Same problem on Ubuntu 20.04 & latest version of SDK

.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-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

For MacOS and netcoreapp3.1, Microsoft.VisualStudio.Web.CodeGeneration.Design 3.1.* is compatible. Microsoft.VisualStudio.Web.CodeGeneration.Design 5.* was not compatible for me. Screen Shot 2021-10-06 at 10 42 05 AM

I still have the same issue on Win10 VS2019 (16.8.5):

 dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.103
 Commit:    72dec52dbd

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.103\

Host (useful for support):
  Version: 5.0.3
  Commit:  c636bbdc8a

.NET SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.509 [C:\Program Files\dotnet\sdk]
  2.1.513 [C:\Program Files\dotnet\sdk]
  2.1.805 [C:\Program Files\dotnet\sdk]
  2.2.109 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]
  5.0.102 [C:\Program Files\dotnet\sdk]
  5.0.103 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <UserSecretsId>aspnet-GreenEdge.Web-642EB634-0E6C-41E6-83FB-A0E080BE11EE</UserSecretsId>
    <CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.3" />
    <PackageReference Include="Microsoft.Identity.Web" Version="1.6.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\GreenEdge.Model\GreenEdge.Model.csproj" />
  </ItemGroup>

</Project>

To reproduce

  1. Right-click project => Add => new Scaffoled Item => Identity => Add
  2. Select Account/Login + Data context class => Add image

If I downgrade teh project to ,Net Core 3.1 and downgrade all ef packages and Microsoft.VisualStudio.Web.CodeGeneration.Design to 3.1.11 it works.

I just upgraded to the latest version of the sdk that was released two days ago. Info:

.NET SDK (reflecting any global.json):
 Version:   5.0.101
 Commit:    d05174dc5a

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

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

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

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

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

Also updated the codegenerator tool, but I still can’t schaffold anything…

I have tried again within a docker container, here is the Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:5.0
RUN dotnet tool install -g dotnet-aspnet-codegenerator
ENV PATH="${PATH}:/root/.dotnet/tools"

WORKDIR /app

COPY TestMvc.csproj .
RUN dotnet restore
COPY . .

CMD dotnet watch run

After starting the container I attach a shell and tried to run these commands without succes:

root@72923d3215d1:/app# 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.22
root@72923d3215d1:/app# dotnet aspnet-codegenerator controller -name TestController
Building project ...
Finding the generator 'controller'...
Running the generator 'controller'...
A file matching the name EmptyController.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.13

TestMvc.csproj:

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
  </ItemGroup>

</Project>

I can confirm that downgrading the dotnet-sdk to 3.1.301-1 fixes the issue on Ubuntu 20.04.1.

This is also a problem in .Net 5.0.100-preview.8 with dotnet-aspnet-codegenerator 5.0.0-preview.8.20419.1, even after installing Microsoft.VisualStudio.Web.CodeGeneration.Design 5.0.0-preview.8.20419.1.

@deepchoudhery any news on documentation for compiling this project?

I have the same problem using Ubuntu 18.04 and net5.0

I have the same problem on Ubuntu 20.04 with -CodeGeneration.Design 5.0 -.NET SDK 5.0.1 trying to scaffold controller -api.

I can confirm that downgrading the dotnet-sdk to 3.1.301-1 fixes the issue on Ubuntu 20.04.1.

Can confirm It also fixes this issue on Ubuntu 16.04

@srinath999 you need to add the --useSqlite or -sqlite flag for the tool to know sqlite is being used. Otherwise it looks for sqlserver.

@cezarlamann , @deepchoudhery I ran into a similar issue on Ubuntu 20.04.1LTS (64bit).

In addition when running,

dotnet aspnet-codegenerator controller -name CandidateController -m Candidate --relativeFolderPath Controllers -api -dc CandidateContext`

it requested me to add Microsoft.EntityFrameworkCore.SqlServer to the project for completing the process even when I am using Sqlite. Please feel free to use the sample projcet to find the issue