将 MVC 3 rc1 Razor cshtml 文件构建操作设置为编译有任何问题吗?
默认构建操作已从“无”更改为“内容”,据我所知是为了支持 Visual Studio 发布/部署。
对于特定项目,我不使用Visual Studio发布/部署方法,也不需要从命令行编译。
将构建操作设置为“Compile”似乎仍然可以编译,并具有编译时错误和针对 cshtml 中的任何编码错误生成警告的额外好处。
与通常的仅运行时错误相比,这似乎有巨大的好处。
如果我将构建操作更改为“编译”,有谁知道我以后会遇到什么问题?
非常感谢..
编辑:除了 VS 部署或命令行编译之外,我不确定将来可能会遇到什么问题,但为了安全起见,我选择了 marcind 在他的评论中提到的预编译选项。我将其标记为最接近的答案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 Razor 文件设置为“编译”应该不起作用(我很惊讶你说它对你有用),因为标记为“编译”的文件会传递到适合您的项目类型的语言编译器。大多数 Razor 文件不是有效的 C# 或 VB 源文件,它们会产生编译器错误。
看起来 VS 确实做了一些奇怪的事情,并且当您从 IDE 编译时并不总是显示错误。但是,当您直接从命令行编译项目时,它总是会失败。
所以回答你的问题
从技术角度来说,“构建操作”需要是“内容”,因为这就是 ASP.NET 发布/部署的工作方式(在早期预览中它是“无”,因为 VS 实际上并不了解有关 Razor 文件的任何信息,这是默认设置行为;“改变”的目的是让事情正常运转)。
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
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).