在两个"MySql.Data问题"中都存在类型"MySqlConnection" [英] The type 'MySqlConnection' exists in both 'MySql.Data Issue
问题描述
我在一个项目上引用了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
项目尚不完全支持程序集的别名.但是,有一种解决方法可以在.net 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 .net 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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!