Question

The default build action has been changed from "None" to "Content", as I understand to support Visual Studio publish/deploy.

For a particular project, I do not use the Visual Studio publish/deploy method, nor need to compile from the command line.

Setting build action to "Compile" still seems to compile, with the added benefit of compile-time errors and warnings being generated for any coding mistakes in the cshtml.

This seems like a huge benefit over the usual runtime-only errors.

If I change the build action to "Compile", does anyone know what issues I will run into later?

Many thanks..

edit: I am not sure what future issues I might run into, other than VS deployment, or commandline compilation, but for safety, I went for the precompile option marcind mentions in his comment. I marked that as the closest answer.

Was it helpful?

Solution

Setting your Razor files to "Compile" should not work (and I'm surprised that you say it does for you) because files that are marked as "Compile" are passed to the language compiler appropriate to your project types. And most Razor files are not valid C# or VB source files and they will produce compiler errors.

It does look like VS is doing something strange and does not always show the error when you compile from the IDE. However, it does always fail when you compile the project directly from the command line.

So to answer your questions

  1. Because it does not work
  2. It won't work (now, or later). In fact, when you publish/deploy your site your Razor files will not be copied.

And to be technical, the "Build Action" needs to be "Content" because that's how asp.net publishing/deployment works (and in earlier previews it was "None" because VS did not actually know anything about Razor files and that's the default behavior; the purpose of the "change" was to make things work at all).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top