aspnet-codegenerator Unhandled Exception: System.InvalidOperationException: Failed to get Project Context
See original GitHub issueTrying to use aspnet-codegenerator to scaffold a razor page as outlined here; https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model
And getting an “Unhandled Exception: System.InvalidOperationException: Failed to get Project Context” for any action. My project is targeting net47
>dotnet aspnet-codegenerator razorpage -h
Unhandled Exception: System.InvalidOperationException: Failed to get Project Context for C:\Dev\Neptune\Neptune.Web\Neptune.Web.csproj.
at Microsoft.Extensions.ProjectModel.MsBuildProjectContextBuilder.Build()
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.<>c__DisplayClass8_0.<Execute>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Execute(String[] args, Boolean isNoBuild, ILogger logger)
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Main(String[] args)
My .csproj looks like the following
<PropertyGroup>
<TargetFramework>net47</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Templating" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Latest Version returns error: "Scaffolding failed. Failed ...
Even when referencing options that do not exist, the error persists as "Failed to get Project Context". When uninstalling codegenerator and ...
Read more >Getting help on dotnet-aspnet-codegenerator debug output
I have compared the .csproj files for the project where codegenerator works against the one where codegenerator fails to get Project Context.
Read more >How do I fix the error: "Unhandled exception. System.IO. ...
The error message indicates you are missing the dotnet-aspnet-codegenerator-design, Version=7.0.6.0 package. You either have to install the ...
Read more >Add a controller to an ASP.NET Core MVC app
We cover these concepts in this tutorial series and show you how to use them to build a movie app. The MVC project...
Read more >Fix Update: Scaffolding failed, could not load information for ...
In this video, I going to fix this error, Scaffolding failed in visual studio dring adding razor view, area etc. so you can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem is that dotnet build fails (see https://github.com/dotnet/cli/issues/8187). So other tools like the Entity Framework ones that return the contexts in the project don’t run. This is also why Apply Migrations checkbox does not appear in Visual Studio Web Publish Settings.
Yep, same problem. Fixed build and problem went away.