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 behaviour just by making changes to the build-configuration or project properties of projects created by Visual Studio 2010, but I have seen that behaviour 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 is 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 definded 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

10 thoughts on “How to get rid of the errors CA0055 and CA0052

  1. How can I specify my search directories? Basically I do have referenced DLLs in my project that lies in different folder than the target.

    I am referring to /d: option in codemetrics

  2. Hi,

    Thanks for your reply. But unfortunately i cannot edit project file, so is it possible to provide some opton that extension can use and pass it to codemetrics exe? basically UI option without modifying project file.

    But none the less, i can continue with this for the time being. Looking forward for your support

    • Hm, maybe it´s a stupid question, but why can´t you customize the project file (which would be a common szenario in software development using Visual Studio and .NET)? The option you´re looking for is already supported by the tool (-: In my opinion, it doesn´t make any sense to provide a tool option (neither in the settings dialog, nor somewhere else), because the /directory setting is related to a project – and not to the tool.

  3. I am having the same issue with CA0055 and CA0052. I am using VS2010 and when I create a standard console application (no code added) the same two errors are generated.

    Look forward to your insight with this one. Thanks.

      • I think it can happen to any project type, but the solution is the same… have a closer look to the project file (as I described) and it will work.

  4. I seem to have provoked something like this by signing an assembly and then rebuilding it without signing it. Projects which used to reference a copy of this DLL which have now been upgraded to the one which is no longer signed seem to look for the old one for code analysis purposes for some reason. This is bizarre, to say the least. (It seems that Microsoft has implemented ten gazilion ways to “load” assemblies, not all corresponding to what one does according to the Framework documentation.)

  5. Thank you for the explanation. Probably is a bug of VS, I had the same problem also on a newly created solution that by default target Any Cpu. I remove all Any Cpu occurrences using project settings editor but a value in the .proj xml was still using Any Cpu.

    I changed

    Any Cpu

    to

    x86

    and now it works.

    Thank you for this addin.

    • Ops some XML tag have been stripped from my comment. The occurrence that I replaced was inside the tag Platform, maybe it could help someone else had the same problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s