存在目标DOES时StyleCop CA0055问题

时间:2012-08-20 21:11:48

标签: c# visual-studio-2010 stylecop

与另一个类似的问题一样,我在构建时遇到两个StyleCop错误:

CA0052:未选择任何目标。

CA0055:无法加载[主exe ...的路径]

但是,与其他问题不同,重新格式化并重新安装我的开发机器上的所有内容并没有解决它。我们正在运行带有SP1的Visual Studio 2010,并以Dotnet 4.0为目标。

这是另一个细节,可以帮助那里的人弄清楚什么是错的:

我也尝试在Visual Studio 2012 RTM下构建解决方案,我得到了第二条错误消息的更详细版本 -

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)

那里有人有任何线索吗?没有其他人得到这个错误,所以在我自己的设置中毫无疑问是奇怪的,当我重新保存我的机器时,我无意中复制了这个错误。但是...什么?

1 个答案:

答案 0 :(得分:2)

我找到了两种方法来解决这个问题,没有任何微软文档的帮助。线索出现在VS 2012的附加错误报告中 - StyleCop无法找到 System.Drawing 程序集。

修复#1:从.csproj文件中删除 HintPath 元素,告诉项目在哪里找到 Windows.Forms 程序集:

<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>

修复#2:添加 HintPath 元素,以便 System.Drawing 包含在.csproj文件中:

<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>

第一个选项对我来说效果更好,因为提示没有特别的原因。 MSBuild能够在没有它的情况下找到程序集,并且它是多余的,因为目标类型设置为框架的4.0版本。

相关问题