本地构建Visual Studio项目遇程序集版本冲突警告,求解决方案
解决.NET Framework 4.7.2下Azure.Core程序集版本冲突警告的方法
问题背景
已配置项目的csproj和package.config为最新依赖版本,开启了AutoGenerateBindingRedirects,但仍出现两个程序集版本冲突警告:
- 提示需将Azure.Core从版本1.34.0.0重定向至1.35.0.0
- 提示存在依赖程序集版本冲突,需开启AutoGenerateBindingRedirects(已开启但无效)
解决步骤
1. 手动添加程序集绑定重定向
自动生成的绑定重定向可能未生效,直接在项目的app.config文件的<runtime>节点内添加以下配置:
<dependentAssembly> <assemblyIdentity name="Azure.Core" publicKeyToken="92742159e12e44c8" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-1.34.0.0" newVersion="1.35.0.0" /> </dependentAssembly>
该配置会强制将所有旧版本的Azure.Core引用指向1.35.0.0版本。
2. 修正csproj中的绑定重定向配置
检查csproj文件内的AutoGenerateBindingRedirects配置格式是否正确,替换现有配置为以下内容(确保在<PropertyGroup>节点内):
<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>
添加GenerateBindingRedirectsOutputType可确保绑定重定向规则被写入输出目录的配置文件。
3. 清理并重建项目
- 执行「清理解决方案」操作
- 手动删除项目目录下的
bin和obj文件夹 - 重新构建整个解决方案,确保新配置生效
4. 排查依赖链中的旧版本引用
打开package.config,确认所有依赖包均未引用Azure.Core 1.34.0.0版本。若存在其他依赖包依赖旧版本,尝试将这些包更新至兼容Azure.Core 1.35.0的版本。
内容的提问来源于stack exchange,提问作者Vinny
相关产品推荐
相关产品推荐

