Publishing Pre-Compiled ASP.net-MVC VS2010

半城伤御伤魂 提交于 2019-12-14 02:08:18

问题


I found several solutions which use Post-Build event.

Is there a way to publish ASP.NET MVC web site with compiled views (to prevent first user view delay) but do not compile them in development environment (to compile site faster)?

Thank you!

P.S. Ideally it would be to configure One Click Publish feature in Visual Studio 2010

Edit

As I understood <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" /> does the same thing as

 <MvcBuildViews>true</MvcBuildViews>
 <EnableUpdateable>false</EnableUpdateable>

but for early versions

My .csproj looks like

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

and views precompile fine but I can't get a single library for deployment like with Asp .net applications. That's why first load page delay still exist...

Please help


回答1:


You can configure the post-build event to compile views only when you compile in Release mode so that it does not slow you down during development (when you presumably compile in Debug mode.)

For example, the following node in a .csproj will only compile views when the project is compiled in Release mode.

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



回答2:


Or you can set MvcBuildViews to true, but only do it for certain configurations:

<MvcBuildViews>true</MvcBuildViews>

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

Notice i've added And '$(Configuration)'!='Debug'" to the condition.



来源:https://stackoverflow.com/questions/8038053/publishing-pre-compiled-asp-net-mvc-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!