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.4dotnet new mvcdotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design -v 3.1.4 && dotnet restore && dotnet builddotnet 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)
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:
Mount it in place of your nuget directory:
Then, after running
dotnet restorethe 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-1dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3This is mydotnet --info`SDK de .NET Core (reflejando cualquier global.json): Version: 3.1.301 Commit: 7feb845744Entorno 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. (?)
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.
@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
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.
I still have the same issue on Win10 VS2019 (16.8.5):
To reproduce
Account/Login+ Data context class => AddIf 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:
Also updated the codegenerator tool, but I still can’t schaffold anything…
I have tried again within a docker container, here is the Dockerfile:
After starting the container I attach a shell and tried to run these commands without succes:
TestMvc.csproj:
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.8withdotnet-aspnet-codegenerator 5.0.0-preview.8.20419.1, even after installingMicrosoft.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.
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,
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