StackExchange.Redis.StrongName is refrenced but no

2019-01-27 15:17发布

I'm starting a new project using StackExchange.Redis and .Net Core 2.0. But I get a conflict:

The type 'ConnectionMultiplexer' exists in both 'StackExchange.Redis.StrongName, Version=1.2.4.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis, Version=1.2.6.0, Culture=neutral, PublicKeyToken=null'

Why is this showing even thou I'm not referencing StackExchange.Redis.StrongName and it's not even the same assembly version?

4条回答
趁早两清
2楼-- · 2019-01-27 15:19

I added a conditional flag to the "StackExchange.Redis" package, that makes it work. I Tried this solution on two new projects on two machines. Don't ask me why it works tho.

    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
      </PropertyGroup>

      <ItemGroup>
        <Folder Include="wwwroot\" />
      </ItemGroup>

      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
      </ItemGroup> 
      <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
        <PackageReference Include="StackExchange.Redis" Version="1.2.6" />
      </ItemGroup>

    </Project>
查看更多
太酷不给撩
3楼-- · 2019-01-27 15:20

It is possible to use Strongname in your entire application, 1.2.6 is newer and will be used. The problem is when you add Redis.Stackexchange you will have the same namespace from two different dll's. .Net compiler doesn't know which one to use. If you need 1.2.6, use the StrongName version throughout your application and no more problems ....

查看更多
地球回转人心会变
4楼-- · 2019-01-27 15:39

I found my solution here.

By adding this (below) to my csproj:

<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
  <ItemGroup>
    <ReferencePath Condition="'%(FileName)' == 'StackExchange.Redis.StrongName'">
      <Aliases>signed</Aliases>
    </ReferencePath>
  </ItemGroup>
</Target>
查看更多
Ridiculous、
5楼-- · 2019-01-27 15:45

Microsoft.Extensions.Caching.Redis 2.0 that ships with Asp .Net Core 2.0 internally uses StackExchange.Redis.StrongName, Version=1.2.4.0, that there is for example in C:\Program Files\dotnet\sdk\NuGetFallbackFolder\stackexchange.redis.strongname\1.2.4\lib\netstandard1.5 folder.

So looks it's causes a conflict between different versions of StackExchange.Redis.

查看更多
登录 后发表回答