程序集绑定重定向和代码分析

发布于 2024-09-30 02:41:11 字数 884 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

只是为了补充一点更精确的答案:

您需要运行 FxCopCmd.exe:

fxcopcmd.exe /assemblyCompareMode:StrongNameIgnoringVersion

或修改每个构建配置的属性组的 Visual Studio 项目文件,如下所示:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  ...
  <CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
</PropertyGroup>

Just to supplement with a little more precise answer:

You need to either run FxCopCmd.exe with:

fxcopcmd.exe /assemblyCompareMode:StrongNameIgnoringVersion

or modify your Visual Studio project file for each build configuration's property group, like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  ...
  <CodeAnalysisAdditionalOptions>/assemblyCompareMode:StrongNameIgnoringVersion</CodeAnalysisAdditionalOptions>
</PropertyGroup>
隱形的亼 2024-10-07 02:41:11

请参阅 http://davesbox.com/archive/2008/06/10/reference-resolution-changes-in-code-analysis-and-fxcop-part-1.aspxhttp://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.

故事还在继续 2024-10-07 02:41:11

除了 peter_raven 解决方案之外,您还可以指定选项以使代码分析与 TFS 构建一起使用。将其添加到“MSBuild Arguments”中的构建选项、进程选项卡、高级类别中:

/p:CodeAnalysisAdditionalOptions=/assemblyCompareMode:StrongNameIgnoringVersion

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

/p:CodeAnalysisAdditionalOptions=/assemblyCompareMode:StrongNameIgnoringVersion
聽兲甴掵 2024-10-07 02:41:11

如果您需要关闭代码分析,请使用此选项。

在 Visual Studio 2012 中,

  1. 右键单击您的项目并从弹出菜单中选择“属性”。
  2. 单击“代码分析”选项卡,然后取消选中“在构建时启用代码分析”

清理和构建。代码分析错误应该消失。

Use this if you need to turn off Code Analysis.

In Visual Studio 2012,

  1. Right click on your project and select "Properties" from the popup menu.
  2. Click on "Code Analysis" tab and uncheck "Enable Code Analysis on Build"

Clean and Build. Code Analysis error should go away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文