4
votes

I'm currently in progress of migrating a class library project to dotnet cli (RC2) from DNX (RC1). Previously, the project referenced the .NET v4.5.1 framework libraries, and the project.json file looks like this:

  "frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.Runtime": "4.0.10.0",
        "System.Web": "4.0.0.0",
        "System.DirectoryServices": "4.0.0.0",
        "System.DirectoryServices.AccountManagement": "4.0.0.0",
        "System.ServiceModel": "4.0.0.0",
        "System.ServiceModel.Security": "4.0.0.0"
      }
    }
  }

Now as far as I'm aware, (and I could be wrong,) unlike DNX, the new dotnet Cli doesn't support .NET 4.5.1, and instead supports .NET Standard.

So problem is, .NET Standard doesn't have all the libraries I want. What do I have to change so I can reference the .NET 4.5.1 framework libraries? I read about the imports statement, but I can't get it to work. Here is what I have so far (updated):

  "frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.Runtime": "4.0.10.0",
        "System.Web": "4.0.0.0",
        "System.DirectoryServices": "4.0.0.0",
        "System.DirectoryServices.AccountManagement": "4.0.0.0",
        "System.ServiceModel": "4.0.0.0",
        "System.ServiceModel.Security": "4.0.0.0"
      }
    },
    "netstandard1.5": {
      "imports": [ "dnxcore50", "portable-net451+win8" ]
    }
  }

I get errors such as this:Cannot reference ParallelQuery

I am a bit lost on what else I need to do... Any ideas?

3

3 Answers

2
votes

dotnet supports net451. Here's an example of application that has both net451 and netstandard.

If you app was running on full desktop in RC1, there should be not problem migrating it to full desktop in RC2.

1
votes

Try rolling with netcoreapp1.0 instead of netstandard1.5.

The new RC2 templates generate the following project.json framework element (by default):

"frameworks": {
  "netcoreapp1.0": {
    "imports": [
      "dotnet5.6",
      "dnxcore50",
      "portable-net45+win8"
    ]
  }
},

There's a little discussion about this on GitHub. To quote richlander:

  • netstandard -> NETStandard.Library (this is expected to work on all .NET
  • netstandardapp -> NETStandard.App (same as NETStandard.Library + app hosts)
  • netcoreapp -> Microsoft.NETCore.App (this is the .NET Core base install)
0
votes

Check on the .NET Platform Standard documentation on GitHub.

The netstandard1.5 target moniker targets .NET 4.6.2, which means you can't run it with .NET 4.5.1 projects.

The correct moniker to target .NET 4.5.1 and above is netstandard1.2.

In essence, the target moniker tells you which framework is the lowest supported. The lower the supported frameworks, the more of them you can target with a single moniker w/o the need of conditional preprocessor directives.

But also, the lower the target moniker, the less of the newer features won't be available (i.e. Task.CompletedTask).

When you need to target a older framework and want to use new functionality you have to use multiple targets, i.e. netstandard1.2 which uses the old api and netstandard1.3 that uses the .NET 4.6+ Api and use conditional preprocessor directives to use new Api calls in a specific target.