简体   繁体   English

如何在.Net Framework 4.6.2应用程序中使用.Net核心类库(.NetStandard v1.5)

[英]How can I use .Net Core Class Library (.NetStandard v1.5) into .Net Framework 4.6.2 Application

According to Mapping the .NET Platform Standard to platforms .NET Platform Standard 1.5 have to be compatible with .NET Framework 4.6.2. 根据将.NET平台标准映射到平台, .NET平台标准1.5必须与.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. 我尝试使用它(创建新的.NET Platform Standard类库,然后创建新的.Net Framework 4.6.2控制台应用程序),但是无法识别该库。 What I am doing wrong? 我做错了什么?

project.json in class library: 类库中的project.json:

{
  "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. 如果你得到最新的.NET核心RTM版本和更新3 VS工具,事情比他们在RC周期更好一点 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. 仍然没有来自cpro引用xproj的简单项目引用-但是,您可以通过将xproj输出打包到nuget软件包中,然后使用软件包管理器来安装该软件包,来进行讨论。 Also, you shouldn't need the imports on the framework, nor the dependency on netstandard.library, at least I don't. 而且,您不需要框架上的导入,也不需要对netstandard.library的依赖,至少我不需要。 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. 创建一个.cmd文件,该文件将打包nuget文件,然后两个文件将输出文件复制到程序包管理器期望它们的文件夹中。 Here's that script, I call it makeNuget.cmd: 这是该脚本,我称其为makeNuget.cmd:

    IF "%1" == "%2" ( IF“%1” ==“%2”(

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

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

    )

  • Add a postbuild script in the project.json of the xproj to run the script 在xproj的project.json中添加一个postbuild脚本以运行该脚本

    "scripts": { “脚本”:{
    "postcompile": [ "makeNuget.cmd %compile:Configuration% Release packages\\%project:Name% %compile:OutputDir% %compile:TargetFramework%" “ postcompile”:[[makeNuget.cmd%compile:Configuration%发布程序包\\%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 这应该使您在解决方案根目录的packages \\ [projectName] \\文件夹中有一个nuget包,而二进制文件则位于packages \\ [projectName] \\ lib \\ [targetFramwork] \\文件夹中

  • 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). 现在,您需要将packages文件夹添加为软件包源,因此首先打开软件包管理器控制台,然后单击小齿轮以添加软件包源(或Ctrl + Q,软件包源,按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] install-package [您的软件包名称]

AFAIK, that's as good as it gets at the moment. AFAIK,这和现在一样好。

Do you really need .Net Framework 4.6.2 app? 您是否真的需要.Net Framework 4.6.2应用程序?

I just created PCL (Portable class library) targeting .NETStandard1.4 and I can use it in WPF app which is targeting .NET Framework 4.6.1. 我刚刚创建了针对.NETStandard1.4的PCL(便携式类库),并且可以在针对.NET Framework 4.6.1的WPF应用中使用它。 Here is how my project.json looks like in PCL project: 这是我的project.json在PCL项目中的样子:

{
  "supports": {},
  "dependencies": {
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.4": {}
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从.NET Framework 4.6.2类库中定位.NET核心类库 - Target .NET Core Class Library From .NET Framework 4.6.2 Class Library 我可以在版本4.6.2的Visual Studio项目中使用针对4.5.1 .net框架的库吗? - Can I use a library which is targeted to 4.5.1 .net framework in a visual studio project of version 4.6.2 .NET Core应用程序中的.NETStandard Library 1.6.0依赖项 - .NETStandard Library 1.6.0 dependency in .NET Core application 如何从.NetStandard类库引用net40框架程序集? - How do I reference net40 framework assembly from .NetStandard class library? 如何在.Net Core类库中使用Rijndael加密? (不是.Net Framework) - How to use Rijndael encryption with a .Net Core class library? (Not .Net Framework) 从.NET Core应用程序引用.NET 4.6.2类库 - Referencing .NET 4.6.2 class library from .NET Core app 在 .NET Framework 4.6.2 中,FormattedText() 已过时,我该如何修复它 - In .NET Framework 4.6.2 the FormattedText() is Obsoleted, how can I fix it 如何在.NET核心应用程序中使用.NET核心类库? - How do I use a .NET core class library in a .NET core application? 我可以在.NET 4.6.2中使用Prism 5吗 - Can I use Prism 5 with .NET 4.6.2 .NET Core netstandard 1.2类库中不存在BindingFlags - BindingFlags does not exist in .NET Core netstandard 1.2 class library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM