Myke Black
Myke Black

Reputation: 1339

Error adding scaffolded controller in asp.net core 1.1 using VS2017

I'm using VS2017 on a brand new ASP.net core web application (version 1.1) and when I try to add 'api controller with actions using entity framework' I get the following error message:

There was an error running the selected code generator: 'Version for package 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' could not be resolved.'

I've googled a bit and found a few suggestions, one of which was to add a CLI tool reference in the .csproj file, so I have added the following:

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" 
         Version="1.0.1" />
</ItemGroup>

This version matched the installed version according to the NuGet package manager. However the problem still persists. Any suggestions on how to fix this please?

Upvotes: 1

Views: 813

Answers (1)

Myke Black
Myke Black

Reputation: 1339

After a few hours of headbanging, I stumbled across this post: System could not be found Visual Studio 2017 ASP.NET Core project

I followed the advice to enable automatic check for missing packages and it finally worked!

I had the same problem, first when converting a VS2015 net core mvc web project to 2017 and then when trying to create a new core web application in 2017.

Went to Tools|NuGet Package Manager|Package Manager Settings - checked 'Allow NuGet to download missing packages' and 'Automatically check for missing packages during build in VS' and then clicked 'Clear All NuGet Cache(s)'. Then re-built the solution - it found and loaded all the required packages and ran OK.

May not work for all cases but simple and worth a try.

Upvotes: 1

Related Questions