Enabling MVCBuildViews based on compilation conditionals
Is it possible to add conditional steps to your build to check for a special compilation conditional and enable MVCBuildViews. I found a way to do this based on the build config, for example
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
but not sure how to access the compilation symbols.
The plan was to add a symbol under Project Settings> New> Compilation Conditional Symbols that control MVCBuildViews
source to share
Assuming you are using C #, you need to configure the compiler to use the Eg symbol .TEST
when creating views, and in order to do this, you need to override its configuration in Web.config
using the following:
<system.codedom>
<compilers>
<compiler
language="c#;cs;csharp"
extension=".cs"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
compilerOptions="/define:TEST" //Here you need to define your symbol
warningLevel="1" />
</compilers>
</system.codedom>
If you apply this directly in Web.config it will work, but will define eg. TEST
everytime. So what you really should be using Web.config transformations
to make sure the symbol is only used for correct build configurations.
You can update projects built with previous versions of MVC to enable Build Mode watch time checking by following these steps:
1) Open the project file in a text editor.
2) Add the following element below the top-most element: <MvcBuildViews>true</MvcBuildViews>
3) At the end of the project file, uncomment the item <Target Name="AfterBuild">
and change it to match the following:
<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
</Target>
source to share