是否可以在构建中添加条件步骤以检查自定义条件编译符号并启用MVCBuildViews。我已经找到了基于构建配置的方法来实现这一点
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
但不确定如何访问编译符号。
计划是在项目设置&gt;下添加符号;构建&gt;控制MVCBuildViews的条件编译符号
答案 0 :(得分:0)
假设您正在使用C#,您需要将编译器配置为在构建视图时使用Eg .TEST
符号,为此您需要使用以下内容覆盖Web.config
中的配置:
<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>
如果直接在Web.config中应用它,它将起作用,但将定义例如。每次TEST
。所以你真正要做的就是使用Web.config transformations
,这样符号才会应用于正确的构建配置。
您可以通过执行以下步骤来更新使用以前版本的MVC创建的项目,以包括视图的构建时验证:
1)在文本编辑器中打开项目文件。
2)在最顶层的元素下添加以下元素:<MvcBuildViews>true</MvcBuildViews>
3)在项目文件的末尾,取消注释<Target Name="AfterBuild">
元素并修改它以匹配以下内容:
<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
</Target>
答案 1 :(得分:0)
您可以尝试这种方法
<MvcBuildViews Condition="'$(Configuration)'=='Release'">true</MvcBuildViews>
<MvcBuildViews Condition="'$(Configuration)'!='Release'">false</MvcBuildViews>