所以我在 MVC 3 RTM 应用程序上编辑了我的 csproj 文件以设置以下属性:
<MvcBuildViews>true</MvcBuildViews>
这应该会导致我的视图在构建期间得到遵守,并在我的 View 被破坏时强制出现构建错误。这是我所做的唯一更改,但是,当我尝试构建应用程序时,出现以下错误:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
如果我改回false,项目编译运行成功,
以下是在csproj文件中配置的构建任务(这些从来没有手动编辑过,它们是由Visual Studio 2010添加的)
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
我是不是漏掉了什么?如何正确配置 MVC 3/Visual Studio 2010 以在构建时验证我的 View ?
最佳答案
几天前我遇到了这个问题,我通过删除 obj/Debug 文件夹修复了它。清理项目也有效。不过,我不知道问题的原因。
参见 Joe Cartano's answer以获得更永久的解决方案。
关于c# - MVCBuildViews 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4725387/