Frage

I have a library published on nuget that is targeting .NET Framework 4.5

The solution looks like:

Solution
  └─ Project.Net45

The nuget package looks like:

─lib
  └─net45

I wanted to add a portable class library, so I modifed the solution to:

Solution
  └─ Project.Net45
  └─ Project.Pcl (Targets Windows Store Apps and Windows Phone 8)

I had to modify the code in the portable class library to work around things that were not compatible with those targets such as the serializable attribute and Thread.Sleep.

The problem is that the portable class library is automatically set to target .NET Framework 4.5 with the following message:

"The following frameworks will be selected automatically because they support all of the available functionality that is portable between the other frameworks you have selected: .NET Framework 4.5 and higher".

and the nuget package now looks like:

─lib
  └─net45
  └─portable-net45+wp80+win

If I install this nuget package into a library targeting .NET Framework 4.5, I would rather the net45 library be used rather than the portable class library as the net45 library is smaller and doesn't have all the extra code needed to work around the missing features in windows phone 8 etc).

Will changing the nuget package to structure below have the desired effect :

─lib
  └─net45
  └─portable-wp80+win

Or am I misunderstanding the usage of portable class libraries?

War es hilfreich?

Lösung

NuGet looks for the best match when adding references to assemblies in the NuGet package.

If your project targets .NET 4.5 then NuGet will install the net45 assembly since it considers that the best match.

The PCL assembly will be used when your NuGet package is added to a PCL project that is compatible.

If you only had the PCL assembly in your NuGet package then NuGet would add a reference to it if you installed it into a project that targets .NET 4.5. However since you have both it will pick the net45 assembly.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top