问题
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