Venkata Dorisala
Venkata Dorisala

Reputation: 5075

Referencing a .NET 4.5.2 class library in .Net Standard 1.6 project

This scenario might be weird. But i want to reference an existing .NET 4.5.2 class library into a new .Net Standard 1.6 class library using Nuget. I cannot see the .Net 4.5.2 class library in Nuget package store at all.

I don't want to migrate any existing projects to .Net Core but want to use them in .Net core projects.

Is it possible to achieve this? Or am i trying to achieve something which is not the purpose of .Net Core.

My project.json is as below.

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "NETStandard.Library": "1.6.0",
    "AutoMapper": "5.0.2",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.VisualStudio.clrdbg": "14.0.25520-preview-3139256"
  },

  "tools" : {
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netstandard1.6": {
         "imports": [ "dnxcore50", "net452" ]
    }
  }
}

UPDATE :

I added net452 section under frameworks. Then i am getting Cannot Resolve errors for few packages already installed. PFA screenshot.

enter image description here

Is there anyway i can force this to to work .

Upvotes: 2

Views: 1118

Answers (1)

user3163840
user3163840

Reputation: 21

You're missing the Net45 import in your framework imports section. If it's a runnable project, then you will need to add the Microsoft.NETCore.App to your dependencies and import the necessary frameworks in order for it to work

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    },
    "AutoMapper": "5.0.2",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.VisualStudio.clrdbg": "14.0.25520-preview-3139256"
  },

  "tools" : {
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "portable-net45+wp80+win8+wpa81+dnxcore50",
        "dnxcore50",
        "net452"
      ]
    }
  },
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
}

However, if you're using a PCL you'll then need to use the netstandard framework and import the necessary frameworks in order for the PCL to build.

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "NETStandard.Library": "1.6.0",
    "AutoMapper": "5.0.2",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.VisualStudio.clrdbg": "14.0.25520-preview-3139256"
  },

  "tools" : {
    "Microsoft.EntityFrameworkCore.Tools": {
     "version": "1.0.0-preview2-final",
     "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": [
        "portable-net45+wp80+win8+wpa81+dnxcore50",
        "dnxcore50",
        "net452"
      ]        
    }
  }
}

Upvotes: 2

Related Questions