3
votes

I have a nuget package http://www.nuget.org/packages/Tavis.UriTemplates/ that has the following nuspec file,

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>Tavis.UriTemplates</id>
    <version>0.4</version>
    <authors>Darrel Miller</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <title>URI Template resolution library</title>
    <description>Implementation of RFC 6570</description>
    <tags>http</tags>
        <releaseNotes>Added PCL version</releaseNotes>
        <projectUrl>https://github.com/tavis-software/UriTemplates</projectUrl>
        </metadata>
    <files>
        <file src="Packages\temp\UriTemplates\lib\Net35\*.*" target="lib\Net35" />
        <file src="Packages\temp\UriTemplates\lib\portable\*.*" target="lib\Portable-Net40+WinRT45+WP71+sl4" />
    </files>
</package>

If I install this package in a project that is .net40 or .net45 it selects the .net 35 DLL. Anyone have any idea why it doesn't select the PCL library?

1
Shouldn't your nuspec have different framework files such as: <file src="bin\release\v3.5*.*" target="lib\net35" /> <file src="bin\release\v4.0*.*" target="lib\net40" />Jon Douglas
@JonDouglas I'm trying to avoid having to build shell projects with linked files just so that I can support .net 40 and .net 45. Seems to defeat the point of PCL libraries if I still have to build separate DLLs for all the full frameworks.Darrel Miller

1 Answers

3
votes

NuGet treats PCL assemblies as less compatible than assemblies that target a specific version of the .NET framework.

For your NuGet package you can either add a .NET 4.0 and a .NET 4.5 assembly or remove the .NET 3.5 assembly.

Looking at the NuGet source code, in the VersionUtility class, a PCL assembly's weighting will be halved compared to an assembly that references the full version of .NET.

// we divide by 2 to ensure Portable framework has less compatibility value than specific framework.
return GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary(projectFrameworkName, packageTargetFrameworkName) / 2;

With your NuGet package, even though the PCL assembly's compatiblity is higher based on the value returned from the GetCompatibilityBetweenPortableLibraryAndNonPortableLibrary method, the division by two makes the .NET 3.5 assembly more compatible.