1

I have an import statement in one of my msbuild project files:

<Import Project="$(ProjectDir)..\CommonProjectProperties\OurCommon.targets" Condition="Exists('$(ProjectDir)..\CommonProjectProperties\OurCommon.targets" />

The imported msbuild project has the following propertygroup:

<PropertyGroup Condition="'$(Configuration)' == 'Debug' And '$(SolutionName)' == 'Ourwork' And Exists('$(ProjectDir)..\..\FXCopSettings\OurGlobal.ruleset')">
    <CodeAnalysisRuleSet>$(ProjectDir)..\..\FXCopSettings\OurGlobal.ruleset</CodeAnalysisRuleSet>
    <RunCodeAnalysis>true</RunCodeAnalysis>
    <CodeAnalysisIgnoreGeneratedCode>True</CodeAnalysisIgnoreGeneratedCode>
    <DefineConstants>$(DefineConstants);CODE_ANALYSIS</DefineConstants>
</PropertyGroup>

And the following item group:

<When Condition="Exists('$(ProjectDir)\..\..\Solutions\FXCopSettings\GlobalSuppressions.cs') And Exists('$(ProjectDir)$(ProjectName).csproj')">
        <ItemGroup>
            <Compile Include="$(ProjectDir)\..\..\Solutions\FXCopSettings\GlobalSuppressions.cs" />
        </ItemGroup>
    </When>

Basically what I am trying to do is to have the above import statement in all my projects files, and then manipulate whether FXCop is run by tweaking just the imported project file.

Problem is that from the command line, all this works fine (with the exception of the constant CODE_ANALYSIS which i have to set using something like msbuild /t:build proj.sln /p:DefineConstants="CODE_ANALYSIS=true". That's fine.

From the VS 2010 IDE its just... hell! It "looks" like VS is respecting all the stuff in the imported msbuild project file.... EXCEPT
1) the included file is greyed out, meaning that is is shown in the IDE only if you have "show all files on". This means that it not compiled. I can copy the exact same ItemGroup into the parent msbuild project file, and the file shows up, un-greyed out, in solution explorer, meaning it is compiled.
2) The suppression file is used to tell FXCop which objects to ignore when it does a code analysis. When I get the suppression file correctly compiled as part of the project, FXCop seems to ignore it. Reading up on this, apparently the CODE_ANALYSIS constant needs to be turned on. Which I thought i did from the imported project file, but it is not being respected. Even though the project properties window in the VS IDE show it is as a defined constant. Again, when i move the DefinedConstansts declaration into one of the parent project files, the IDE respects the constant.

So... I am not sure whether i need to separate this into two posts, but here are my questions:
1) how do i get the IDE to respect and compile files listed in an imported project file?
2) how do i get the IDE to respect DefineConstants in an imported project file

0 Answers0