【问题标题】:StyleCop CA0055 issue when target DOES exist存在目标时的 StyleCop CA0055 问题
【发布时间】:2012-08-20 21:11:48
【问题描述】:

与另一个类似的问题一样,我在构建时遇到两个 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)

有人有线索吗?没有其他人收到此错误,因此在我自己的设置中无疑是一件奇怪的事情,并且在我重新铺设我的机器时无意中复制了它。但是……什么?

【问题讨论】:

标签: c# visual-studio-2010 stylecop


【解决方案1】:

我找到了两种解决此问题的方法,但没有任何 Microsoft 文档的帮助。线索在 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:添加 System.DrawingHintPath 元素包含在 .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 版本的框架。

【讨论】:

    猜你喜欢
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多