如何将 .Net Core 类库 (.NetStandard v1.5) 用于 .Net Framework 4.6.2 应用程序 [英] How can I use .Net Core Class Library (.NetStandard v1.5) into .Net Framework 4.6.2 Application

查看:28
本文介绍了如何将 .Net Core 类库 (.NetStandard v1.5) 用于 .Net Framework 4.6.2 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据

  • 在包管理器控制台中,确保在顶部的下拉菜单中选择了包源和项目.
  • install-package [你的包名]
  • AFAIK,就目前而言,这是最好的.

    According to Mapping the .NET Platform Standard to platforms .NET Platform Standard 1.5 have to be compatible with .NET Framework 4.6.2. I have tried to use it (make new .NET Platform Standard class library, then new .Net Framework 4.6.2 console application), but the library is not recognized. What I am doing wrong?

    project.json in class library:

    {
      "version": "1.0.0-*",
    
      "dependencies": {
        "NETStandard.Library": "1.5.0-rc2-24027"
      },
    
        "frameworks": {
            "netstandard1.5": {
                "imports": "dnxcore50",
                "buildOptions": { "embed": "true" }
            }
        }
    }
    

    解决方案

    If you get the latest .net core RTM release and the Update 3 VS tooling, things are a little nicer than they were during the RC period. Still don't have easy project references from csproj referencing xproj - but, you can get things to talk by packing up the xproj output into a nuget package, then using the package manager to install that package. Also, you shouldn't need the imports on the framework, nor the dependency on netstandard.library, at least I don't. Here's how I've done it:

    • Create a .cmd file which will package the nuget files and two copy the output files to the folder where the package manager is expecting them. Here's that script, I call it makeNuget.cmd:

      IF "%1" == "%2" (

      dotnet pack --no-build --configuration %1 -o ../%3

      xcopy %4 "...\%3lib\%5" /Y

      )

    • Add a postbuild script in the project.json of the xproj to run the script

      "scripts": {
      "postcompile": [ "makeNuget.cmd %compile:Configuration% Release packages\%project:Name% %compile:OutputDir% %compile:TargetFramework%"
      ] }

    This should leave you with a nuget package in the packages[projectName] folder at the root of your solution, with the binaries in the packages[projectName]lib[targetFramwork] folder

    • Now, you need to add the packages folder as a package source, so first open the package manager console, then click the little gear to add a package source (or Ctrl+Q, package sources, Enter). Then click the add button, name this source, browse or type in the packages directory and hit ok.
    • In the package manager console, make sure both your package source and project are selected in the drop downs at the top.
    • install-package [your package name]

    AFAIK, that's as good as it gets at the moment.

    这篇关于如何将 .Net Core 类库 (.NetStandard v1.5) 用于 .Net Framework 4.6.2 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆