1

I have a C# project that relegates code to Portable Libraries projects, so they can be reused in .Net and Silverlight environments seamlessly.

The PCLs target .Net45 and Silverlight 5.

Now I want to use the same PCLs in .Net Core environment. If possible, I want to keep my solution with .Net and Silverlight environments and reuse the Portable projects in a new .Net Core solution.

When I try to add a reference to a regular PCL project from a .Net Core Library, it fails to read the dependency.

NU1001 The dependency could not be resolved.

If I attempt to add a reference to the PCL assembly I get an error:

.NET Core projects only support referencing .NET framework assemblies in this release. To reference other assemblies, they need to be included in a NuGet package and reference that package.

Is it possible to use regular PCLs on .Net Core environment? Or I need to create new .Net Core libraries?

If I need to create new projects, how can I avoid duplicated code?

pmoleri
  • 4,238
  • 1
  • 15
  • 25
  • 1
    It is possible to use PCLs in a .NET Core project using the `import` keyword (see [docs](https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md#portable-profiles)). The easiest way to test this would be to create a Nuget package of your PCL library and attempt to reference it in `project.json`. – Nate Barbettini Jun 27 '16 at 23:52
  • Thanks @NateBarbettini, but I'm already targeting the same PCL moniker and doesn't allow me to reference a PCL project, importing the same moniker would be pointless, doesn't it?. Creating a NuGet package would remove the reference to the projects itself. – pmoleri Jun 28 '16 at 23:17
  • I has the same problem. This [link](http://stackoverflow.com/questions/31900713/how-do-i-use-a-standard-class-library-in-mvc6) will help you. – Salman Lone Jul 18 '16 at 11:23

2 Answers2

0
  1. Go to add reference
  2. Browse the project which you want to refer.
  3. Select the .dll of the project instead of the project itself.
  4. Add .dll reference and build.
Salman Lone
  • 1,526
  • 2
  • 22
  • 29
  • Thanks, but when I attempt to do that in a .Net Core project I get the error described in the post `.NET Core projects only support referencing .NET framework assemblies in this release...` – pmoleri Jul 19 '16 at 13:50
  • Then i think you need to migrate your PCL project in .net core first and then use the it in your .net core project. – Salman Lone Jul 20 '16 at 06:28
  • Yes, I agree, that would work, the only problem is that I'll miss a few features present en `.csproj` that aren't available in `project.json` as custom tools for resource files and file linking. – pmoleri Jul 20 '16 at 14:17
0

Try this link. Here you can make an API of version 4.5.2 and call that API in your .net core project. That API will work as a bridge in your old class library and .net core application. the hosting of your class library will become separate. I think this will work in your case.

Salman Lone
  • 1,526
  • 2
  • 22
  • 29