11

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?

Dave New
  • 38,496
  • 59
  • 215
  • 394
  • _should they all target dnx451 or does only the web project need to target dnx451? Could the class libraries just target net451?_ ... so what happened when you tried these scenarios? – jltrem Aug 05 '15 at 14:02
  • @jltrem: It builds in VS but breaks on `dnu publish` in my integration build with some ArgumentNullException [as posted here](http://stackoverflow.com/questions/31802998/dnu-publish-system-argumentnullexception-value-cannot-be-null). – Dave New Aug 05 '15 at 14:17

4 Answers4

7

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

Rune Antonsen
  • 159
  • 1
  • 9
Gekctek
  • 1,161
  • 2
  • 12
  • 23
  • And are dnx451 and net451 compatible with each other since they both use .NET Framework 4.5.1? – Dave New Aug 06 '15 at 02:44
  • That I don't know for sure and haven't tested but anything that is dnx is going to be deployed with the solution as a runtime or be installed as a specific runtime for a user while net451 is going to be installed in Windows. As far as I know they are the same thing but I don't know if the VS or the compiler will identify then as the same thing for dependencies – Gekctek Aug 06 '15 at 06:48
  • `dnxcore` uses the .NET Core Framework which is "bin deployable". I believe that `dnx` is different to `dnxcore` in that is uses the desktop version of .NET Framework. I just don't know which version of the framework and how it fits in with ASP.NET 5! – Dave New Aug 06 '15 at 07:13
  • 4
    This is not really answering the stated question which was more about the difference between `dnx451` and `net451`, not `dnxcore` and `dnx451` (the latter is clear to me - they are completely different frameworks - but the former still isn't). – Vojtěch Vít Jan 24 '16 at 11:53
  • for Test project such as `xunit`, you will need `dnx451` and `dnxcore50` http://xunit.github.io/docs/getting-started-dnx.html – Jaider Feb 17 '16 at 05:17
3

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

Daniel Little
  • 16,975
  • 12
  • 69
  • 93
2

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/

Thomas
  • 5,080
  • 27
  • 42
0

You library must support all the frameworks that you web project it targeting. This is why the default Class Library project in VS15 targeting dotnet, which is supporting the widest ranges of frameworks.

Xiaowei.Jia
  • 415
  • 1
  • 4
  • 13