Search code examples
.net.net-4.0.net-4.5portable-class-library

PCL - can I target .NET 4.5 and ".NET 4.0 with BCL extensions"


I have a Portable Class Library project which currently targets the following platforms:

  • .NET Framework 4.5
  • Windows 8
  • Windows Phone Silverlight 8

I'd like to add support for .NET 4.0, but I currently use some .NET features, which are only available in .NET 4.0 through inclusion of the "Microsoft BCL Portability Pack"; features like the CallerMemberName attribute, the IProgress interface, and the updated Task class.

Is there a way to add some 'conditional' support for a platform, in a PCL project? I.e. "allow .NET 4.0, as long as dependency XXXXX is included?"


Solution

  • As mentioned in the comments, target .NET 4 in the PCL and reference the Microsoft.Bcl and probably Microsoft.Bcl.Async packages.

    You can consider packaging up your PCL as a NuGet package with those packages listed as a dependency. That way when your NuGet package is installed in a project the required Microsoft.Bcl packages will also be installed.