[英]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] \\文件夹中
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.