程序集绑定重定向和代码分析
我在 Visual Studio 2010 的 Mvc 3.0.0.0 项目中使用 DotNetOpenAuth (引用 System.Web.Mvc 版本 1.0.0.0)。
我使用程序集绑定重定向,如下所示:-
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
一切正常,除了代码分析给出我犯了以下错误:-
CA0001:读取模块 X 时遇到以下错误:无法解析程序集引用:System.Web.Mvc、Version=1.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35。
和
CA0058:找不到引用的程序集“System.Web.Mvc,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”。该程序集是分析所必需的,并由:X 引用。
有没有办法让代码分析工具尊重程序集绑定重定向?
I'm using DotNetOpenAuth (which references System.Web.Mvc version 1.0.0.0) in a Mvc 3.0.0.0 project in Visual Studio 2010.
I'm using assembly binding redirection as follows:-
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Everything works fine, except code analysis which gives me the following errors:-
CA0001 : The following error was encountered while reading module X: Assembly reference cannot be resolved: System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
and
CA0058 : The referenced assembly 'System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be found. This assembly is required for analysis and was referenced by: X.
Is there a way to get the code analysis tool to respect the assembly binding redirection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只是为了补充一点更精确的答案:
您需要运行 FxCopCmd.exe:
或修改每个构建配置的属性组的 Visual Studio 项目文件,如下所示:
Just to supplement with a little more precise answer:
You need to either run FxCopCmd.exe with:
or modify your Visual Studio project file for each build configuration's property group, like this:
请参阅 http://davesbox.com/archive/2008/06/10/reference-resolution-changes-in-code-analysis-and-fxcop-part-1.aspx 和 http://davesbox.com/archive /2008/06/14/reference-resolutions-changes-in-code-analysis-and-fxcop-part-2.aspx 了解一些背景信息。
在 VS2010/FxCop 10.0 中,fxcopcmd.exe 有一个新的 / assemblyCompareMode 命令行开关,允许您指定比较模式,而无需修改 .config 文件。您可以使用 CodeAnalysisAdditionalOptions MSBuild 属性在 VS 项目中指定这一点。
See http://davesbox.com/archive/2008/06/10/reference-resolution-changes-in-code-analysis-and-fxcop-part-1.aspx and http://davesbox.com/archive/2008/06/14/reference-resolutions-changes-in-code-analysis-and-fxcop-part-2.aspx for a bit of background information.
In VS2010/FxCop 10.0, there's a new /assemblyCompareMode command line switch for fxcopcmd.exe that allows you to specify the comparison mode without mucking about with the .config file. You can specify this in you VS project by using the CodeAnalysisAdditionalOptions MSBuild property.
除了 peter_raven 解决方案之外,您还可以指定选项以使代码分析与 TFS 构建一起使用。将其添加到“MSBuild Arguments”中的构建选项、进程选项卡、高级类别中:
In addition to peter_raven solution you can specify option to make Code Analysis work with TFS build. Add this in build options, process tab, advanced category in "MSBuild Arguments":
如果您需要关闭代码分析,请使用此选项。
在 Visual Studio 2012 中,
清理和构建。代码分析错误应该消失。
Use this if you need to turn off Code Analysis.
In Visual Studio 2012,
Clean and Build. Code Analysis error should go away.