【问题标题】:Generic Debug/Release Tag in csproj Filecsproj 文件中的通用调试/发布标记
【发布时间】:2014-07-10 16:59:08
【问题描述】:

我们的项目使用 StyleCop 来执行编码标准。我们的目标是将所有 StyleCop 警告视为错误。但是,我们只想在发布版本上强制执行此操作。由于代码一直在变化,直到开发人员准备好执行签入,我们不希望 StyleCop 错误抱怨甚至可能无法进入源代码控制的代码段。

目前我们必须在我们的 csproj 文件中执行此操作:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
  <StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>

目前我必须在每个配置组合上设置StyleCopTreatErrorsAsWarnings。是否有一个通用的发布和调试标签,我可以使用它在所有调试版本上将StyleCopTreatErrorsAsWarnings 设置为true,在所有发布版本上而不是单独设置false

【问题讨论】:

  • 当然,它是 $(Configuration)。只需从您的测试中删除 |$(Platform)。
  • 我觉得自己像个白痴。这很有道理。

标签: c# visual-studio-2013 stylecop csproj


【解决方案1】:

正如Hans Passant所说,解决方法是添加以下PropertyGroup标签。

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  <StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
  <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多