Our project uses StyleCop to enforce coding standards. Our goal is to treat all StyleCop warnings as errors. However we only want to enforce this on Release Builds. Since code is constantly in flux until a developer gets ready to perform a check-in, we don't want StyleCop errors complaining about segments of code that may not even make it into source control.
Currently we have to do this in our csproj files:
<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>
Currently I have to set StyleCopTreatErrorsAsWarnings
on every configuration combination. Is there a generic Release and Debug tag that I can use to set StyleCopTreatErrorsAsWarnings
to true
on all debug builds and false
on all release builds instead of individually?
As mentioned by Hans Passant, the solution is to add the following PropertyGroup
tags.
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>