简体   繁体   English

支持.NET 4.5和DotNetCore

[英]Support .NET 4.5 and DotNetCore

How can I support .NET 4.5 and DotNetCore? 如何支持.NET 4.5和DotNetCore?

Is a PCL for shared code the best way forward (if at all possible to target DNX + .NET 4.5)? 用于共享代码的PCL是最好的前进方式(如果有可能以DNX + .NET 4.5为目标)吗?

Basically I have a library I publish as a NuGet package which still needs to support .NET 4.5.2, but I want to use this library in a DotNetCore application as well. 基本上,我有一个以NuGet包形式发布的库,该库仍需要支持.NET 4.5.2,但我也想在DotNetCore应用程序中使用该库。

Is this something the .NET Standard will help with? .NET标准是否可以帮助您解决此问题? Or is .NET standard only for .NET Core+? 还是.NET仅适用于.NET Core +?

In .NET Core you can select your build target, and library used. 在.NET Core中,您可以选择构建目标和使用的库。 All those changes are made in project.json. 所有这些更改都是在project.json中进行的。

To add support for .NET 4.52 you need to modify your project.json to look something like this 要添加对.NET 4.52的支持,您需要修改project.json以使其看起来像这样

"frameworks": {
"netcoreapp1.0": { //Support for .NET Core
  "imports": "dnxcore50",
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    }
  }
},
"net452": { //Support for .NET 452
}

To add platform specific code for .NET 452 use 为.NET 452使用添加特定于平台的代码

#if NET452
...
#endif

To run with .NET 452 use this command 要与.NET 452一起运行,请使用此命令

dotnet run -f NET452

On MSDN they have pretty good documentation about this topic and a lot of others. MSDN上,他们有关于此主题以及许多其他主题的很好的文档。

This Article also explains very good how to manage Core and normal .NET code in one project. 文章还介绍了很好的如何在一个项目管理的核心和正常的.NET代码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM