4

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.

Leon van der Walt
  • 997
  • 12
  • 18

1 Answers1

4

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).

marcind
  • 52,944
  • 13
  • 125
  • 111
  • Thanks for the reply. Updated the question to qualify that I do not use publish/deploy. Also changed "it still works" to "still seems to compile" - because it does, successfully, unless you make syntax errors in the cshtml. I think this is tremendously useful, but can't seem to find any documentation on it.. – Leon van der Walt Nov 18 '10 at 19:13
  • Can you try compiling your app from the command line? Open up a VS command line, go to your project directory, and run `msbuild ProjectName.??proj`. – marcind Nov 18 '10 at 19:27
  • 2
    Btw, there already is a facility for precompiling your views: http://stackoverflow.com/questions/383192/compile-views-in-asp-net-mvc – marcind Nov 18 '10 at 19:32
  • Thanks for the precompile option, thats whats needed! Sorry for not being more exact in the question. Edited to qualify that I do not need commandline compilation either. You have answered the first part of my question, upvote for that and for the reference, thanks. – Leon van der Walt Nov 19 '10 at 11:55