0

Here is the project.json for the main dotnet core web project

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

If I add the following net461 class library project as a reference to above one. It won't build correctly.

 "frameworks": {
    "net461": {
    }
  }

and throw error like The dependency mscorlib could not be resolved.

However, if I create a project by using the old template(no project.json), and add it as a reference to dotnet core project. It works fine.

I wonder how to fix this?

svick
  • 236,525
  • 50
  • 385
  • 514
maxisam
  • 21,975
  • 9
  • 75
  • 84
  • 1
    I didn't understand what you are trying to achieve. In the upper code section you are targeting .NET Core and .NET Framework (But you still cannot use all of your bins\libs of .NET Framework in .NET Core, at least not yet) and in the bottom you are referencing just .NET Framework not .NET Core. Are you trying to use .NET Framework libraries instead of CoreFx? – Janshair Khan Jun 01 '16 at 19:56
  • @JanshairKhan I am trying to create a .net framework library and use it as a reference to .net core web project. – maxisam Jun 01 '16 at 22:07

1 Answers1

4

What you're doing is creating a library that will run only on .Net Framework, and then trying to use it from an application that runs on .Net Core. That won't work.

If you want to run on .Net Core, then project.json of your application should contain:

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

And library (the version of netstandard will depend on what you want to do):

"frameworks": {
    "netstandard1.4": {
    }
}

If you want to use dotnet CLI, but still run on .Net Framework, then have the following in both your library and application (where you include framework assemblies inside frameworkAssemblies):

"frameworks": {
  "net461": {
    "frameworkAssemblies": {
    }
  }
}
svick
  • 236,525
  • 50
  • 385
  • 514
  • Déjà-vu ;) Same problem twice a day. – Thomas Jun 01 '16 at 20:23
  • I think I misunderstood the meaning of import section. I thought it means it allows you to use the including framework library. – maxisam Jun 01 '16 at 22:12
  • @maxisam `imports` basically bypasses compatibility checks. If the library actually is compatible, but doesn't appear to be, then it works. But if the library is not actually compatible, `imports` won't help you. – svick Jun 01 '16 at 22:36
  • so you mean net461 is actually not compatible with netcoreapp1.0 ? I thought it supports to net463. – maxisam Jun 01 '16 at 22:51
  • @maxisam Yes, `net` and `netcoreapp` are not compatible. But both are compatible with `netstandard`, so that's what you should use in your libraries, if you can. – svick Jun 01 '16 at 22:54
  • 1
    @svick but if I have a reference that doesn't support netstandard, like mysql.data, the only option is to use net461 all the way ? – maxisam Jun 01 '16 at 23:10
  • 1
    @maxisam Yes, exactly. – svick Jun 01 '16 at 23:13