Home Why do dotnet command line builds fail on MVC View errors but VS2017 does not?
Reply: 1

Why do dotnet command line builds fail on MVC View errors but VS2017 does not?

Mourndark Published in 2018-02-08 11:07:26Z

I'm working on a .NET Core 2 MVC project in VS2017. I've noticed that when building with the command line, any C# errors in my Razor views cause the build to fail. However when building in VS2017 the build will run fine. If I have a .cshtml file open that contains C# errors, they will show as errors in the error list, but they won't stop the build from completing.

I'm not sure why I'm getting two different results as surely both are using MSBuild under the hood? Is there a way I get VS to fail on Razor C# errors in the same way as the command line does?

CalC Reply to 2018-02-08 14:02:12Z

With ASP.NET Core 2.x Razor, views can be precompiled on publish if the Microsoft.AspNetCore.Mvc.Razor.ViewCompilation package is included (setting the MvcRazorCompileOnPublish to true is optional). It is not currently possible to compile views as part of a standard debug build.

For further details see Razor view compilation and precompilation in ASP.NET Core

If your project targets .NET Framework, include a package reference to Microsoft.AspNetCore.Mvc.Razor.ViewCompilation:

<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" />

Prepare the app for a framework-dependent deployment by executing a command such as the following at the project root:

> dotnet publish -c Release

A .PrecompiledViews.dll file, containing the compiled Razor views, is produced when precompilation succeeds.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311519 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO