Trying to resolve dependencies: Changing .NET Standard Library to NET Core - Microsoft.Extensions.Primitives

醉酒当歌 提交于 2019-12-25 07:50:03

问题


I am running Visual Studio 2015 Update 3. I am trying to use Redis Cache for .Net core applications. Since, the developed package is targeting .Net Standard Library. I downloaded the code from github and trying to change the dependecies my self.

Here are the projects:

First, I am trying to chage the Abstractions Class Library to target .Net Core, then i tried to add the Microsoft.Extensions.Primitives, Since the version 1 does not support .NET Core. I added the final pre package:

Install-Package Microsoft.Extensions.Primitives -Version 1.0.0-rc1-final -Pre

It cannot resolve, saying that

The dependency Microsoft.Extensions.Primitives >= 1.0.0-rc1-final could not be resolved.

How Can I fix that to make it work for .NET Core? How is .NET Core 1 different from .NET Core 5, since these are dependencies of the package I installed?

Why all the packages support .NET Standard Libary and not .NET Core?


回答1:


Dunno what exactly you're doing, but rc1 references seem wrong, now that ASP.NET Core RTM is out for several months.

I grabbed the 1.0.0 sourced (you have to specifically choose the 1.0.0 tag. Master branch is based on ASP.NET Core 1.1).

Only thing I changed is project.json (I unloaded the other unloaded unrelated projects and test projects except Microsoft.Extensions.Caching.Redis.Test.

This is my project.json (of Microsoft.Extensions.Caching.Redis):

{
  "version": "1.0.0",
  "description": "Distributed cache implementation of Microsoft.Extensions.Caching.Distributed.IDistributedCache using Redis.",
  "packOptions": {
    "repository": {
      "type": "git",
      "url": "https://github.com/aspnet/caching"
    },
    "tags": [
      "cache",
      "distributedcache",
      "redis"
    ]
  },
  "buildOptions": {
    "warningsAsErrors": true,
    "keyFile": "../../tools/Key.snk",
    "nowarn": [
      "CS1591"
    ],
    "xmlDoc": true
  },
  "dependencies": {
    "Microsoft.Extensions.Caching.Abstractions": "1.0.0",
    "Microsoft.Extensions.Options": "1.0.0",
    "StackExchange.Redis.StrongName": "1.1.608"
  },
  "frameworks": {
    "netstandard1.5": { },
    "net451": {
      "dependencies": { },
      "frameworkAssemblies": {
        "System.Runtime": {
          "type": "build"
        }
      }
    }
  }
}

No changes required in Microsoft.Extensions.Caching.Abstractions.

Alternatively you can use StackExchange.Redis instead of StackExchange.Redis.StrongName which isn't strong named (signed). Not sure if the so created/compiled package will be signed with the same key as the other packages, which may create issues later. If you use unsigned one then it also may create issues, if your application is strong named itself (or you have business requirement that all assemblies are strong signed).

This compiles and the unit tests pass, didn't test further.

As for the rest of your question:

".NET Core 5" nuget target is dnx50 which was used up until ASP.NET Core rc1. With rc2 ASP.NET Core switched to the dotnet-cli and DNX is unsupported now and won't receive any further updates. With rc2 the netstandard was introduced to simplify creation of class libraries which can target most of the platforms available (full .NET Framework, .NET Core, WinRT/WindowsPhone/Windows8/Windows10, mono, Xamarin, etc). You can learn more about the .NET Standard Library.



来源:https://stackoverflow.com/questions/40386962/trying-to-resolve-dependencies-changing-net-standard-library-to-net-core-mic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!