In my test project, I import an msbuild targets file which defines stylecop rules. This style cop rule targets file imports the standard stylecop targets file, which is checked in to our source code repo (so everyone always has the same stylecop version). I use absolute paths to reference files, where the paths are rooted at the environment variable %inetroot%. I open VS with this environment variable set.
I have warnings as errors set to true in each project, which through the target files I use enables stylecop warnings as errors as well. This works in Visual Studio and with MSBuild at the command line. However, NCrunch builds fail with stylecop errors. The errors I am getting are for things like including documentation on private fields, which are not part of the stylecop rule set I am using.
So, in my test project, I have this (much of it omitted for brevity):
Code:
<Project …>
…
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
…
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
…
<Import Project="$(inetroot)\build\msbuild\StyleCop.Targets" />
…
</Project>
And in the file StyleCop.Targets I have this:
Code:
<Project …>
…
<!-- If the project has the TreatWarningsAsErrors flag set, then treat StyleCop violations as errors as well. -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<SourceAnalysisTreatErrorsAsWarnings Condition="'$(TreatWarningsAsErrors)' == 'true'">false</SourceAnalysisTreatErrorsAsWarnings>
</PropertyGroup>
<Import Project="$(INETROOT)\build\tools\StyleCop\v4.5\StyleCop.Targets" />
…
</Project>
I used the Advanced menu -> Browse to workspace last built for selected project. I can see that NCrunch has replicated the directory structure of my project and the target files it references, so that I have these files:
NCrunch\31804\19\build\msbuild\StyleCop.Targets
NCrunch\31804\19\test\AssemblyName\AssemblyName.csproj
But there is no NCrunch\31804\19\build\tools\StyleCop\v4.5\StyleCop.Targets file in the workspace. So it seems like NCrunch only copied the msbuild imports 1 level deep. Is this a known limitation, or is there another reason that this file would not be copied to the NCrunch workspace?
If I use msbuild at the command line to build the project in the NCrunch workspace (with %inetroot% set the same as it is when I run VS), it fails with all the stylecop errors, just like it does from within NCrunch. So, it seems like the problem stems from the workspace.
I can workaround this by putting a condition on the treat warnings as errors tag so that it is not set when NCrunch = 1, but I would prefer not to have to do this for all of the project files because there are many of them.
I am using VS 2010 and NCrunch 1.40.0.24b.