发现无法解析的“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”之间存在冲突
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
关注让【宝码香车】来帮您解答,本回答参考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.config或web.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-transitive5. 更新目标框架
确保项目文件中的目标框架一致:
<PropertyGroup> <TargetFramework>net5.0</TargetFramework> </PropertyGroup>6. 清理和重建
dotnet clean dotnet build选择适合你项目情况的解决方案,通常从配置绑定重定向开始尝试。
解决 无用评论 打赏 举报