在两个"MySql.Data问题"中都存在类型"MySqlConnection"

编程入门 行业动态 更新时间:2024-10-28 18:30:11
本文介绍了在两个"MySql.Data问题"中都存在类型"MySqlConnection"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在一个项目上引用了MySql.Data,其他项目引用了nuget包,该包在其中也引用了MySqlConnector.项目具有依赖性.

I have Referenced MySql.Data on one project and Other project referenced nuget package which also referenced MySqlConnector inside of it. projects has dependency .

当我编译应用程序时遇到此错误

when i compile application im getting this error

这是应用程序层次结构

有什么办法可以避免这种情况?还是引用软件包时我做错了什么?

is there any way to avoid this? or did i do anything wrong when referencing packages?

谢谢

更新 这是来自不同库的相同名称空间

UPDATE this is the same namespaces from difference libs

更新2

这是示例存储库,它复制了同一期问题

This is the sample repo which reproduced same issue

推荐答案

在NET.Framework项目中,您可以转到引用属性并为程序集设置别名. Net core项目尚不完全支持程序集的别名.但是,有一种解决方法可以在 core中使用别名.像这样编辑您的csproj文件:

In NET.Framework projects you can go to the reference properties and set an alias for assembly. Net core projects doesn't fully support yet aliases for assemblies. But there is a workaround to use aliases in core. Edit your csproj file like this:

<Project Sdk="Microsoft.NET.Sdk.Web"> ... <Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences"> <ItemGroup> <ReferencePath Condition="'%(FileName)' == 'MySqlConnector'"> <Aliases>MySqlConnectorAlias</Aliases> </ReferencePath> </ItemGroup> </Target> ... </Project>

然后在所有使用之前将您的cs文件中的内容保存

then in your cs file before all usings:

extern alias MySqlConnectorAlias;

然后您可以像这样从MySqlConnector中引用您输入的内容:

then you can reference to you type from MySqlConnector like this:

MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlConnection

更多推荐

在两个"MySql.Data问题"中都存在类型"MySqlConnection"

本文发布于:2023-11-04 10:02:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中都   两个   类型   quot   Data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!