VS.NET 2017 forces using StackExchange.Redis 1.2.4

2019-02-25 02:42发布

I am using Visual Studio 2017. I just created a new ASP.NET Core 2.0 project. I was trying to use NuGet to pull in the latest StackExchange.Redis 1.2.6 (as of 9/3/2017).

However, once I do that, Visual Studio complains that there is a conflicted reference in one of my RedisResult variable. It said

Error CS0433 The type 'RedisResult' 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' Server C:\git\Splash\Server\BackPlaneConnection\Channel.cs 19 Active

Then, I found out that I don't really need to manually add any NuGet package in order to use StackExchange.Redis in my ASP.NET Core 2.0 app. In fact, if I manually add a reference to a different version of StackExchange.Redis, it causes the resolve conflict that I showed above.

Checked the build output. The DLL is actually coming from C:\Program Files\dotnet\sdk\NuGetFallbackFolder\stackexchange.redis.strongname

I tried deleting stackexchange.redis.strongname but it somehow still download it to my personal nuget folder automatically.

It almost feels like ASP.NET Core 2.0 internally needs StackExchange.Redis 1.2.4.0 but this really doesn't make sense to me.

I don't have the same problem when using ASP.NET Core 1.1. Is there any way to let my ASP.NET Core 2.0 use the latest StackExchange.Redis from NuGet?

3条回答
Lonely孤独者°
2楼-- · 2019-02-25 03:13

I added a conditional flag to the "StackExchange.Redis" package, that makes it work. I Tried this fix 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>

I gave the same answer in my duplicate question

查看更多
Fickle 薄情
3楼-- · 2019-02-25 03:14

I just ran into a similar problem in a solution file with a number of projects in it. A nuget package had been added which contained a dependency to a *.StrongName.dll version of a package that was already included in one of the projects. Since it was a dependency, tracking down where the StrongName version was referenced was extremely difficult even though it appeared in the Object Browser. I was finally able to track it down using a PowerShell console to dig through all nuget project dependencies in all projects to find the source of the duplication:

dir -Recurse **\project.assets.json | Select-String -pattern "{{dll name}}"
查看更多
Root(大扎)
4楼-- · 2019-02-25 03:32

Found the reason. It's because by default VS.NET 2017 turned on the "Allow NuGet to download missing packages". The build screen also mentioned that.

Restoring NuGet packages... To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.'

In my case, to completely avoid this problem, I need to do the following steps to resolve my problem.

  1. Go to Visual Studio Options dialog.
  2. Uncheck "Allow NuGet to download missing packages" to avoid downloading the NuGet package automatically in the future
  3. Open NuGet Manager to add the latest StackExchange.Redis package
  4. Click "Clear All NuGet Cache(s)" to clean up the old NuGet cache
查看更多
登录 后发表回答