Wing
Wing

Reputation: 6108

StyleCop CA0055 issue when target DOES exist

As with another, similar question, I am getting two StyleCop errors on build:

CA0052: No targets were selected.

CA0055: Could not load [path to main exe...]

But, unlike the other question, reformatting and reinstalling everything on my dev machine did NOT fix it. We are running Visual Studio 2010, with SP1, and targeting Dotnet 4.0.

Here's another detail that may help someone out there figure out what's wrong, though:

I also tried building the solution under Visual Studio 2012 RTM, and I got a more detailed version of the second error message -

CA0055  Error Running Code Analysis 

CA0055 : Could not load C:\Users\UserName\SourceCode\ProjectName\Debug\xxx.exe. 
The following error was encountered while reading module 'System.Windows.Forms': 
Could not resolve type reference: [System.Drawing, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a]System.Drawing.BitmapSuffixInSatelliteAssemblyAttribute.

[Errors and Warnings]

(Global)

Anyone out there have any clues? No one else is getting this error, so it is undoubtedly something odd in my own setup, and which I inadvertantly replicated when I repaved my machine. But...what?

Upvotes: 4

Views: 4786

Answers (2)

srk
srk

Reputation: 1901

I was getting a similar issue.

Environment = Visual Studio 2019, .NET Framework 4.6.2

Error:

3>  Running Code Analysis...

3>MSBUILD : error : CA0055 : Could not load C:\path\to\project\bin\Release\MyProject.dll.

Fixed by adding this to the csproj file for all relevant build configurations:

<RunCodeAnalysis>false</RunCodeAnalysis>

Upvotes: 0

Wing
Wing

Reputation: 6108

I found two ways to fix this, with no help whatsoever from any of Microsoft's documentation. The clue was in VS 2012's additional error reportage - StyleCop could not locate the System.Drawing assembly.

Fix #1: remove the HintPath element from the .csproj file telling the project where to find the Windows.Forms assembly:

<Reference Include="System.Windows.Forms"> 
    <!--<HintPath>..\..\..\..\..\..\..\..\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll</HintPath>-->
</Reference>

Fix #2: add a HintPath element for the System.Drawing include in the .csproj file:

<Reference Include="System.Drawing">
    <HintPath>..\..\..\..\..\..\..\..\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll</HintPath>
</Reference>

The first option worked better for me, because there is no particular reason for the hint. MSBuild is able to find the assembly without it, and it's redundant, since the target type is set the 4.0 version of the framework.

Upvotes: 2

Related Questions