2014-07-10 52 views
1

我們的項目使用StyleCop來實施編碼標準。我們的目標是將所有StyleCop警告視爲錯誤。但是,我們只想在發佈版本上強制執行此操作。由於代碼在開發人員準備執行簽入之前一直處於不斷變化的狀態,因此我們不希望StyleCop錯誤對可能無法進入源代碼管理的代碼段抱怨。csproj中的通用調試/發佈標籤文件

目前,我們不得不這樣做在我們的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在所有的配置組合。是否有一個通用的Release和Debug標籤,可用於在所有版本上將StyleCopTreatErrorsAsWarnings設置爲true,在所有版本上設置false而不是單獨設置?

+1

當然,它是$(配置)。只需從您的測試中移除| $(平臺)。 –

+0

我覺得自己像個白癡。這很有道理。 – lumberjack4

回答

1

正如Hans Passant所述,解決方案是添加以下PropertyGroup標籤。

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