Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. dnx451 is especially intended for DNX runtime application and supports 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? Could the class libraries just target net451?

like image 673
Dave New Avatar asked Aug 05 '15 13:08

Dave New


3 Answers

Update

Per https://github.com/aspnet/Announcements/issues/98 the naming has changed a bit.

For RC1 applications and test projects should still target dnx4x and dnxcore50 and don't need to change at all. Anything that has a Program.Main or Startup.cs is considered an application.

Only class libraries should change to target net4x and dotnet5.x. For class libraries the recommended conversion steps are:

In project.json:

Change dnx4x to net4x (e.g. dnx451 to net451)

Change dnxcore50 to dotnet5.4

And in your CS files:

Change #if DNX451 to #if NET451

Change #if DNXCORE50 to #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:

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

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

Then library1 must support dnx451 and dnxcore50

If I want to reference library1 but it only supports dnx451 then this is my only option:

"dependencies": {
},

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

But that would mean the library1 code could not be used in 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

like image 128
Gekctek Avatar answered Oct 11 '22 18:10

Gekctek


The monikers dnx451 or net451 are essentially the same thing.

They were renamed at some point so, dnxcore50 became dotnet5.4 and dnx451 became net451.

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

like image 25
Daniel Little Avatar answered Oct 11 '22 19:10

Daniel Little


If your class library does not depend on a specific behavior of the .Net SDK (e.g. DNX or the full .Net Framework) you should target dotnet. But that only works with the newer SDKs (.Net 4.6, UWP and DNX),

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

like image 41
Thomas Avatar answered Oct 11 '22 19:10

Thomas