asp.net mvc4 设置build项目时,编译view页面

时间:2024-07-20 22:35:56

新建好项目后,把system.web.mvc.dll移除,重新选择本地C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies下的system.web.mvc.dll,编译出现问题提示:“The type or namespace name 'Html' does not exist in the namespace 'System.Web.Mvc'”

切换回来对应新建时应用目录下的system.web.mvc.dll依然出现问题。

让view重新编译:

1,)修改web解决方案.csproj文件,

1.1,)设置MvcBuildViews属性为true;

<MvcBuildViews>true</MvcBuildViews> 

1.2,)在</Project>前面加上以下内容:

     <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
</Project>

,之后重新编译,问题就解决了。