How to get rid of the errors CA0055 and CA0052

During the last weeks, some users were complaining about the error messages CA0055 and CA0052, which will be reported by the Power Tool, if an invalid target file is specified. The extension tries to obtain the assembly filename from the project file by using MSBuild property evaluation (it´s looking for the TargetPath-property). In some situations, the property evaluation fails, if the OutputPath- and PlatformTarget-property is not specified. In that case, the evaluated value of the TargetPath-property will only contain the name of the output assembly file, but not the full path.

I couldn´t simulate that behavior just by making changes to the build configuration or project properties of projects created by Visual Studio 2010, but I have seen that behavior in some older projects which were created using the 2005/2008 version and upgraded to a Visual Studio 2010 solution. The interesting thing is that this problem can´t be fixed by cleaning up build- and platform configuration using the Visual Studio dialogs because Visual Studio won´t change any customized (or manually added) elements within the project file (which is good). So, we have to fix this problem by manually editing the project file… Don´t worry – this is quite easy (-:

Open the project file using an editor of your choice… if you´re using Power Commands for Visual Studio, you can use the “Edit Project File” command. You´ll find a property group containing an element named “Platform” having a condition, which ensures that a valid value is specified. In the following example the value “x86” will be used, if the property is empty (correct me, if I am wrong, but I think this is the default configuration for Windows Forms and WPF applications created by Visual Studio 2010).

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{E1FAB955-3610-4315-BE54-DAF9EE9F4533}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>WindowsFormsApplication1</RootNamespace>
    <AssemblyName>WindowsFormsApplication1</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>

Okay; this will work if you have another property group like this…

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>

This property group depends on the Platform- and Configuration properties defined earlier; if the values are “x86” and “Debug”, the properties of this group will be defined and can be evaluated by MSBuild. If you´re using a different platform configuration like “Any CPU” and/or “Release”, the evaluation will fail and the Power Tool can´t analyze the assembly. Notice that Platform and PlatformTarget are not the same (-:

Depending on your build configuration, you can add more property groups having different conditions. For example…

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
    <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
  </PropertyGroup>

To cut a long story short: Make sure, that you´ve defined at least one property group that matches with the default values of the Configuration- and Platform properties. This property group must contain the OutputPath- and PlatformTarget-properties. A good verification of the project file is to build it using MSBuild from the command line (without any additional switches).

So, now it´s up to you to fix your project file(s)…

Advertisements

How to get results for code behind XAML-files

In June, a user reported a problem where he does not see any results for code behind XAML files. I dove into the problem and figured out that code behind XAML files was handled by the power tool like generated code, which I had disabled by default using the /igc switch. The latest version of the tool allows to take control over the switch; if you want to calculate code metrics for generated code you have to make sure, that the /igc option is disabled.