zhweCZ 2025-10-19 16:47 采纳率: 0%
浏览 14

发现无法解析的“WindowsBase”的不同版本之间存在冲突。 “WindowsBase, Version=4.0.0.0”与“WindowsBase, Version=5.0.0.0”之间存在冲突

发现无法解析的“WindowsBase”的不同版本之间存在冲突。 “WindowsBase, Version=4.0.0.0”与“WindowsBase, Version=5.0.0.0”之间存在冲突

  • 写回答

4条回答 默认 最新

  • 宝码香车 优质创作者: JavaScript技术领域 2025-10-19 16:49
    关注

    让【宝码香车】来帮您解答,本回答参考DeepSeek编写,并整理提供。

    如果答案让您满意,请采纳、点赞、关注,非常感谢!
    .
    每日一句正能量,让它带给您好心情:相信自己,你远比想象中更有潜力。
    .

    这是一个典型的 .NET 程序集版本冲突问题。当项目中引用的不同组件分别依赖不同版本的 WindowsBase 时,就会出现这种冲突。

    解决方案

    1. 检查项目文件中的引用

    .csproj 文件中检查是否有显式的 WindowsBase 引用:

    <Reference Include="WindowsBase, Version=4.0.0.0" />
    

    <PackageReference Include="Microsoft.WindowsDesktop.App.WindowsForms" Version="5.0.0" />
    

    2. 统一版本引用

    .csproj 文件中添加统一的程序集绑定重定向:

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

    3. 手动配置绑定重定向

    app.configweb.config 中添加:

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="WindowsBase" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    4. 检查 NuGet 包依赖

    运行以下命令查看包依赖关系:

    dotnet list package --include-transitive
    

    5. 更新目标框架

    确保项目文件中的目标框架一致:

    <PropertyGroup>
      <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>
    

    6. 清理和重建

    dotnet clean
    dotnet build
    

    选择适合你项目情况的解决方案,通常从配置绑定重定向开始尝试。

    评论

报告相同问题?

问题事件

  • 创建了问题 10月19日