I am working on a class library that uses EpPlus and freeimage-dotnet-core nuget packages in dotnet core 2.1. But when i want to use Image
object in my code the below error is shown:
Error CS0433 The type 'Image' exists in both 'System.Drawing-dotnet-core, Version=1.2.3.0, Culture=neutral, PublicKeyToken=null' and 'System.Drawing.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
EpPlus uses System.Drawing.Common dll and freeimage-dotnet-core uses System.Drawing-dotnet-core, because of that in my class library "system.drawing" namespace determined in 2 dlls.
I know it is possible to use 'extern alias xyz
', but it works on dotnet framework full version,not in dotnet core.
in Dotnet core projects, in visual studio we cannot see properties of a dll reference.
I solved the problem with adding an alias for one of my referenced libraries with this codes in .csproj file:
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'System.Drawing-dotnet-core'">
<Aliases>DrawingCore</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
<ItemGroup>
<PackageReference Include="System.Drawing-dotnet-core" Version="1.2.3" Alias="DrawingCore" />
</ItemGroup>
Thnanks to: @Damien_The_Unbeliever