3

I am using Visual Studio 2015. I have created a PCL project. Class Library Portable (IOS, Android and Windows). This PCL is a simple POCO class.

It targets: .NET Framework 4.5, ASP.NET Core 1.0, Windows Phone Silverlight 8, Xamarin.Android, Xamarin.IOS

My PCL is referenced by a Xamarin.IOS app and I want to use the same PCL in my Web API.

I am trying to reference this PCL project from an ASP.NET 5 Web API.

The following is in my project.json:

"dnx451": { "dependencies": { "MyPCL": "1.0.0-*" } }

But I get this error:

Error: The Dependency could not be resolved.

I have tried adding the following under frameworks too but no luck.

".NETPortable,Version=v4.0,Profile=Profile111": {

    "dependencies": {
         "MyPCL": "1.0.0-*"
       }
     
  "frameworkAssemblies": {
    "mscorlib": "",
    "System": "",
    "System.Core": ""
  }
}

I have also tried dnu restore... still does not work.

So I upgraded to RC2, but it does not resolve the issue. In project.json now I have:

   "dependencies": 
   {
       "NETStandard.Library":  "1.5.0-rc2-24027"
   } 

and I added the following under framework:

"netstandard1.5": {
  "imports": "dnxcore50"
}

when I compile my Web API project I get the following 3 errors:

  1. the project has not been restored or restore failed. (though I did run dotnet restore)

  2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section.

  3. Cannot find runtime target for framework '.NETStandard,Version=v1.5' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'

Does anyone know how to resolve this issue?

Is it even possible to reference this PCL from an ASP.NET Core Web API or MVC 6 project?

4
  • 1
    Please upgrade to ASP.NET Core RC2 first, dot.net Then use the new framework names and imports statements to consume existing PCL libraries. RC1 is dead and you should leave it behind. Commented Jun 5, 2016 at 6:59
  • I upgraded to RC2. no luck. project.json: "dependencies": { "NETStandard.Library": "1.5.0-rc2-24027" } I added the following under framework: "netstandard1.5": { "imports": "dnxcore50" } Commented Jun 5, 2016 at 16:38
  • when I compile my Web API project I get the following 3 errors: 1. the project has not been restored or restore failed. (though I did run dotnet restore) 2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section. 3. Can not find runtime target for framework '.NETStandard,Version=v1.5' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64' Commented Jun 5, 2016 at 16:39
  • I think you misunderstood the question. the question was referencing one PCL library by both: IOS App and .NET Core MVC. As to NETStandard.Library this is a formal specification of .NET APIs to be available on all .NET runtimes. Commented Jul 14, 2016 at 2:49

1 Answer 1

1
+50

I think your best approach is to:

Upgrade this PCL to a netstandard 1.3+ library. This however would force you to create/upgrade to a netcore 1.0+ MVC/API application to consume as interface INetCoreApp10 : INetStandard15 is the best analogy to think of with netcore projects(Current version is 1.1).

For more information on how to upgrade, you can view the following: https://blog.xamarin.com/net-standard-library-support-for-xamarin/

Please note that if you do this, you can also use the Compatibility Shim to reference other PCLs inside the netstandard library.

https://learn.microsoft.com/en-us/dotnet/articles/standard/library#pcl-compatibility

To answer your question:

Is it even possible to reference this PCL from an ASP.NET 5 Web API or MVC 6 project?

Yes it is. There are many ways to do it and I personally think the correct way is to use the "new" bits such as netstandard and netcore in this situation. Based off my answer you have multiple things you can do:

  1. Upgrade the PCL to netstandard and the API project to netcore. The netcore project can easily consume the netstandard project.
  2. Upgrade the API project to netcore and use the Compatibility Shim to reference old PCL Profiles.
  3. Stay using pre-netcore/netstandard project types and consume the PCL in a ASP.NET MVC 5 Web API project. This is also known as a netframework project rather than netcore. i.e. https://learn.microsoft.com/en-us/dotnet/articles/standard/choosing-core-framework-server
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.