代码之家  ›  专栏  ›  技术社区  ›  Megrez7

NuGet更新后的程序集冲突

  •  0
  • Megrez7  · 技术社区  · 7 年前

    我有一个.Net Framework 4.7.1web表单应用程序和.netframework4.7.1。WebJob,都在Azure AppService上运行。

    自从通过Nuget WebJob包从2.0.0更新到2.2.0之后,出现了许多依赖性问题。

    第一个在运行时出现:

    System.IO.FileLoadException : Could not load file or assembly 'System.Net.Http, Version=4.1.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference

    第二个在编译过程中显示:

    Consider app.config remapping of assembly 对于许多程序集,如System.Net.Http、System.Net.Sockets、System.IO.Compression等。

    为了解决这个问题,我添加了一些源代码和编译器警告

    <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
    </PropertyGroup>
    

    这允许执行WebJob,但编译器在重新映射程序集时仍显示警告。

    自我相信.Net标准以来,我看到了有关程序集冲突的更多问题。

    你能给我解释一下吗 一。程序集发生了什么,为什么我需要打开绑定重定向? 2。为什么这不能解决第二个问题?

    谢谢您。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Joey Cai    7 年前
    1. 程序集发生了什么,为什么我需要打开绑定重定向?

    requires assembly binding redirects 在构建过程中需要生成的。在您将此添加到webjobs之后,它将在您生成时将程序集添加到bin文件夹中。

    1. 为什么这不能解决第二个问题?

    看来这是一个VS问题,你可以通过点击来解决 Migrate packages.config to PackageReference 在你的网络作业引用中。在webjobs中添加以下.csproj并编译。

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net461</TargetFramework>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.Azure.WebJobs" Version="2.2.0" />
      </ItemGroup>
    </Project>
    

    有关更多详细信息,请参阅 issue .