Solution to error – Package ‘Microsoft.VisualStudio.Web.CodeGeneration.Tools’ has a package type ‘DotnetCliTool’ that is not supported by project

Attempting to Scaffold a database for use in a .net core MVC web app has turned in to a headache! Luckily, dear reader, I’ve suffered so you can avoid the pain.

The first thing to do is to make sure your .csproj file contains the following DotNetCliToolReference elements. In Visual Studio Community you can right click on your project –> Tools –> Edit File.

 <ItemGroup>
   <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
   <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
 </ItemGroup>

Now even though Visual Studio will report that “Packages restored successfully” it turns out that the package “Microsoft.VisualStudio.Web.CodeGeneration.Tools” is actually a Command Line Interface (CLI) package that won’t be restored.
To make matters more confusing, if you try and add this Package through the Project –> Add Nuget packages… UI you’ll receive an error!

To restore the package successfully you must open up Terminal/Command Prompt/Bash and cd into your Project directory (not the Solution directory). Here you can run the command

dotnet restore

Once this command completes running, you can now execute the following command to verify that the Entity Framework CLI tool has been installed.

dotnet ef -h

Now you can go ahead and run your scaffold command!

Handy page https://www.learnentityframeworkcore.com/walkthroughs/existing-database

Authors note: I’m using the Npgsql EF Core Provider to connect to my PostgreSQL database. Additionally, there was a lot of googling before anyone mentioned manually running dotnet restore.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.