[英]Visual Studio 2012 Code Analysis Error CA0058
I am currently working on a solution with multiple projects in it, and when I try to run the code analysis tool from VS12 I get the following error when trying to run it: 我目前正在开发一个包含多个项目的解决方案,当我尝试从VS12运行代码分析工具时,我在尝试运行它时遇到以下错误:
CA0058 Error Running Code Analysis CA0058 : The referenced assembly "Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be found.
CA0058运行代码分析错误CA0058:找不到引用的程序集“Microsoft.Practices.Unity,Version = 2.1.505.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”。 This assembly is required for analysis and was referenced by: C:\\MyProject\\bin\\Release\\MyProject.exe, C:\\MyProject\\packages\\Prism.UnityExtensions.4.1.0.0\\lib\\NET40\\Microsoft.Practices.Prism.UnityExtensions.dll.
此程序集是分析所必需的,并通过以下方式引用:C:\\ MyProject \\ bin \\ Release \\ MyProject.exe,C:\\ MyProject \\ packages \\ Prism.UnityExtensions.4.1.0.0 \\ lib \\ NET40 \\ Microsoft.Practices.Prism.UnityExtensions .dll文件。 [Errors and Warnings] (Global)
[错误和警告](全球)
I also got two more erros: 我还有两个错误:
CA0052: No targets were selected
CA0052:未选择任何目标
and 和
CA0055 Error Running Code Analysis CA0055 : C:\\MyProject\\bin\\Release\\IntraEUA Management Software 2.0.exe The following error was encountered while reading module "Microsoft.Practices.Prism.UnityExtensions": Assembly reference cannot be resolved: Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
CA0055运行代码分析时出错CA0055:C:\\ MyProject \\ bin \\ Release \\ IntraEUA管理软件2.0.exe读取模块“Microsoft.Practices.Prism.UnityExtensions”时遇到以下错误:无法解析程序集引用:Microsoft.Practices。 Unity,Version = 2.1.505.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35。 [Errors and Warnings] (Global)
[错误和警告](全球)
But the strange thing is, nowhere in my solution I use ersion 2.1.505.0 of UnityExtensions, I am using 4.1.0.0. 但奇怪的是,在我的解决方案中我没有使用ersion 2.1.505.0的UnityExtensions,我使用的是4.1.0.0。 And even stranger, in all other projects in this solution it works, using the exact same version of UnityExtensions, even the PublicKeyToken is identical in all the other projects.
甚至更奇怪的是,在这个解决方案的所有其他项目中,使用完全相同的UnityExtensions版本,甚至PublicKeyToken在所有其他项目中都是相同的。
I've tried to search the entire solution for the string "2.1.505.0" and found nothing., so where does VS get this Information? 我试图在整个解决方案中搜索字符串“2.1.505.0”并没有找到任何内容。所以VS在哪里获取此信息?
Btw, I got UnityExtension using NuGet. 顺便说一下,我使用NuGet获得了UnityExtension。 And tried to delete and reinstall UnityExtensions, but with no effect.
并尝试删除并重新安装UnityExtensions,但没有任何效果。 And I am using .NET 4.5.
我正在使用.NET 4.5。
Any idea to get rid of this, probably false error? 任何想法摆脱这个,可能是错误的错误? Or at least a workaround to ignore it?
或者至少有一种解决方法可以忽略它?
The underlying issue is due to the combination of two facts: 根本问题是由于两个事实的结合:
Prism.UnityExtensions
version 4.1.0.0
references Unity
in version 2.1.505.0
, with a strong name, but you have a newer version, strongly signed with version 3.0.0.0
; Prism.UnityExtensions
版本4.1.0.0
引用版本2.1.505.0
Unity
,具有强名称,但您有一个较新的版本,与版本3.0.0.0
强烈签名; Meaning that, this mess is not your fault, simply the result of attempting to use an "unexpected" combination of library versions, and of an oversight in FxCop's assembly resolution logic. 这意味着,这个混乱不是你的错,只是试图使用库版本的“意外”组合,以及FxCop的汇编解析逻辑中的疏忽。
The main way to get past that issue is to set FxCop's AssemblyReferenceResolveMode
to StrongNameIgnoringVersion
. 解决该问题的主要方法是将FxCop的
AssemblyReferenceResolveMode
设置为StrongNameIgnoringVersion
。 There are ways to achieve that, one on a per-machine setting, and the other on a per-project setting. 有一些方法可以实现这一点,一个在每台机器上设置,另一个在每个项目设置上。
AssemblyReferenceResolveMode
to StrongNameIgnoringVersion
in either FxCopCmd.exe.config
(from VS12 invocation) or FxCop.exe.config
(command-line call to FxCop.exe
); FxCopCmd.exe.config
(来自VS12调用)或FxCop.exe.config
(命令行调用FxCop.exe
)中将AssemblyReferenceResolveMode
设置为StrongNameIgnoringVersion
; .csproj
file, inside of a PropertyGroup
XML element: PropertyGroup
XML元素内的每个.csproj
文件中添加一行: <PropertyGroup>
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
</PropertyGroup>
I would recommend using the per-project setting for any project that you intend to share with other people. 我建议您为要与其他人共享的任何项目使用每个项目设置。
The only solution to get rid of this is indeed changing the AssemblyReferenceResolveMode of the FxCopCmd.exe.config from StrongName to StrongNameIgnoreVersion . 摆脱这个唯一的解决办法确实改变FxCopCmd.exe.config从强名称到StrongNameIgnoreVersion的AssemblyReferenceResolveMode。 I didn't came up with anything else, so I've got to live with that.
我没有想出任何其他的东西,所以我必须接受它。
I've had this case recently as well. 我最近也有这个案子。 The problem was the following: My debug build configuration for project that raised the error targeted the
any CPU
platform. 问题如下:我的项目的调试构建配置引发了针对
any CPU
平台的错误。 Changing this to the value x86
like the other projects from the solution had solved the problem. 像解决方案中的其他项目一样将其更改为值
x86
已解决了该问题。
The settings can be found in Visual Studio: * right-click the solution to open the context menu within the solution explorer * select properties, the solution property pages dialog is loaded * The settings that you are looking for are here: Configuration Properties
>> Configuration
可以在Visual Studio中找到这些设置:*右键单击解决方案以打开解决方案资源管理器中的上下文菜单*选择属性,加载解决方案属性页对话框*您要查找的设置如下:
Configuration Properties
>> Configuration
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.