简体   繁体   English

在类库项目中定位框架dnx451或net451

[英]Target framework dnx451 or net451 in class library projects

From what I understand, the target frameworks dnx451 and net451 both use the desktop .NET Framework 4.5.1. 据我所知,目标框架dnx451net451都使用桌面.NET Framework 4.5.1。 dnx451 is especially intended for DNX runtime application and supports ASP.NET 5. dnx451特别适用于DNX运行时应用程序,并支持ASP.NET 5。

If we have a solution with a ASP.NET 5 project and multiple class libraries, should they all target dnx451 or does only the web project need to target dnx451 ? 如果我们有一个ASP.NET 5项目和多个类库的解决方案,它们是否都应该针对dnx451或者只有web项目需要针对dnx451 Could the class libraries just target net451 ? 类库是否只针对net451

Update 更新

Per https://github.com/aspnet/Announcements/issues/98 the naming has changed a bit. 根据https://github.com/aspnet/Announcements/issues/98 ,命名发生了一些变化。

For RC1 applications and test projects should still target dnx4x and dnxcore50 and don't need to change at all. 对于RC1应用程序和测试项目,仍然应该针对dnx4x和dnxcore50,并且根本不需要更改。 Anything that has a Program.Main or Startup.cs is considered an application. 任何具有Program.Main或Startup.cs的东西都被视为应用程序。

Only class libraries should change to target net4x and dotnet5.x. 只有类库应该更改为目标net4x和dotnet5.x。 For class libraries the recommended conversion steps are: 对于类库,建议的转换步骤是:

In project.json: 在project.json中:

Change dnx4x to net4x (eg dnx451 to net451) 将dnx4x更改为net4x(例如,dnx451更改为net451)

Change dnxcore50 to dotnet5.4 将dnxcore50更改为dotnet5.4

And in your CS files: 在您的CS文件中:

Change #if DNX451 to #if NET451 将#if DNX451更改为#if NET451

Change #if DNXCORE50 to #if DOTNET5_4 将#if DNXCORE50更改为#if DOTNET5_4


If you have a project that targets multiple frameworks and want to add a general reference to a library, the library must support all those frameworks. 如果您有一个针对多个框架的项目,并且想要添加对库的一般引用,那么该库必须支持所有这些框架。 If you specify that a certain framework itself references that library, then that library only needs to support the chosen framework. 如果指定某个框架本身引用该库,那么该库只需要支持所选框架。

Example if i want to reference library1 for all my frameworks: 示例,如果我想为我的所有框架引用library1:

"dependencies": {
    "library1": "1.0.0"
},

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }
}

Then library1 must support dnx451 and dnxcore50 然后library1必须支持dnx451和dnxcore50

If I want to reference library1 but it only supports dnx451 then this is my only option: 如果我想引用library1但它只支持dnx451那么这是我唯一的选择:

"dependencies": {
},

"frameworks": {
    "dnx451": {
        "dependencies": {
           "library1": "1.0.0"
        }
     },
    "dnxcore50": { } 
}

But that would mean the library1 code could not be used in dnx451. 但这意味着library1代码无法在dnx451中使用。

To work around that you could use is using compile time conditionals: 要解决这个问题,可以使用编译时条件:

#if DNX451
    //Code here for dnx451
#elif DNXCORE50
    //code here for dnxcore50
#endif

Or another work around is using another library for the other dependency 或者另一种解决方法是将另一个库用于其他依赖项

And just to clarify, the library can support more frameworks than your project. 只是为了澄清,该库可以支持比您的项目更多的框架。 So library1 can support dnx451 and dnxcore50 while your project only supports dnx451 and it will be fine 所以library1可以支持dnx451和dnxcore50,而你的项目只支持dnx451,它会很好

The monikers dnx451 or net451 are essentially the same thing. 绰号dnx451或net451基本上是相同的。

They were renamed at some point so, dnxcore50 became dotnet5.4 and dnx451 became net451 . 它们在某些时候被重命名,因此, dnxcore50成为dotnet5.4dnx451成为net451

For reference: https://github.com/aspnet/Announcements/issues/98 供参考: https//github.com/aspnet/Announcements/issues/98

If your class library does not depend on a specific behavior of the .Net SDK (eg DNX or the full .Net Framework) you should target dotnet . 如果您的类库不依赖于.Net SDK的特定行为(例如DNX或完整的.Net Framework),那么您应该以dotnet目标。 But that only works with the newer SDKs (.Net 4.6, UWP and DNX), 但这只适用于较新的SDK(.Net 4.6,UWP和DNX),

http://oren.codes/2015/06/09/pcls-net-core-dnx-and-uwp/ http://oren.codes/2015/06/09/pcls-net-core-dnx-and-uwp/

You library must support all the frameworks that you web project it targeting. 您的库必须支持您针对其进行Web项目的所有框架。 This is why the default Class Library project in VS15 targeting dotnet, which is supporting the widest ranges of frameworks. 这就是VS15中针对dotnet的默认类库项目,它支持最广泛的框架。

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

相关问题 从ASP.NET 4.6创建对net451 xproj类库的项目引用 - Create Project Reference to net451 xproj Class Library from ASP.NET 4.6 如果dnx版本大于451,为什么xUnit测试在Test Explorer中不可见? - Why does xUnit tests are not visible in Test Explorer if dnx version is > to 451? 将DNX类库引用添加到ASP.NET 4 Web应用程序 - Add DNX class library reference to an ASP.NET 4 web application DNX:当前的运行时目标框架与项目不兼容 - DNX: The current runtime target framework is not compatible with project DNX Core 5.0库可针对任何平台。 没有System.Random类。 解决方法或选项? - DNX Core 5.0 library to target any platform. No System.Random class. Workarounds or options? 创建.net类库时不支持的框架错误 - Unsupported framework error creating .net Class library 使用VS2015工具安装.NET Core 1.0(预览版)后,我无法创建.NET核心类库项目 - After installing .NET Core 1.0 with VS2015 tooling (preview), I am unable to create .NET core class library projects 如何在 Visual Studio 中切换 .NET Core 项目的目标框架 - How to switch between target frameworks for .NET Core projects in Visual Studio 类库包:sl5目标问题 - Class Library Package : sl5 target issue 如何在同一解决方案中从4.6.1项目引用多目标.NET Core类库? - How do I reference a multi-target .NET Core class library from a 4.6.1 project within the same solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM