发布预编译的ASP.net-MVC VS2010

时间:2011-11-07 14:46:32

标签: asp.net-mvc visual-studio-2010 deployment

我找到了几个使用Post-Build事件的解决方案。

有没有办法发布 ASP.NET MVC网站带有编译视图(以防止第一次用户查看延迟)但不编译他们在开发环境中(更快地编译网站)?

谢谢!

P.S。理想情况下,在Visual Studio 2010中配置“单击发布”功能

修改

据我了解<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />

完全相同
 <MvcBuildViews>true</MvcBuildViews>
 <EnableUpdateable>false</EnableUpdateable>

但是对于早期版本

我的.csproj看起来像

...
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <MvcBuildViews>true</MvcBuildViews>
    <EnableUpdateable>false</EnableUpdateable>
...

和视图预编译很好但我无法像Asp .net应用程序那样获得单个库进行部署。这就是为什么第一次加载页面延迟仍然存在...

请帮忙

2 个答案:

答案 0 :(得分:2)

只有在发布模式下编译时,才能配置构建后事件以编译视图,这样在开发过程中(当您可能在调试模式下编译时)不会减慢速度。

例如,.csproj中的以下节点仅在以发布模式编译项目时编译视图。

  <Target Name="AfterBuild" Condition="'$(Configuration)'=='Release'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
  </Target>

答案 1 :(得分:0)

或者您可以将MvcBuildViews设置为true,但仅针对某些配置执行此操作:

<MvcBuildViews>true</MvcBuildViews>

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true' And '$(Configuration)'!='Debug'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

注意我已将And '$(Configuration)'!='Debug'"添加到条件中。

相关问题