将 MVC 3 rc1 Razor cshtml 文件构建操作设置为编译有任何问题吗?

发布于 2024-10-03 07:29:04 字数 371 浏览 0 评论 0原文

默认构建操作已从“无”更改为“内容”,据我所知是为了支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2024-10-10 07:29:04

将 Razor 文件设置为“编译”应该不起作用(我很惊讶你说它对你有用),因为标记为“编译”的文件会传递到适合您的项目类型的语言编译器。大多数 Razor 文件不是有效的 C# 或 VB 源文件,它们会产生编译器错误。

看起来 VS 确实做了一些奇怪的事情,并且当您从 IDE 编译时并不总是显示错误。但是,当您直接从命令行编译项目时,它总是会失败。

所以回答你的问题

  1. 因为它不起作用
  2. 它不会起作用(现在或以后)。事实上,当您发布/部署站点时,您的 Razor 文件不会被复制。

从技术角度来说,“构建操作”需要是“内容”,因为这就是 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文