Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Dependency Framework Targeting not working when packaging using the .csproj

Tags:

c#

.net

nuget

I have a NuGet .nuspec that looks like this:

    <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
    <metadata>
        <id>XXXXXXXXX</id>
        <version>1.0.0-alpha</version>
        <authors>XXXXXXXXX</authors>
        <owners>XXXXXXXXXXX</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>XXXXXXXXXXXXXXXXXXX</description>
        <copyright>XXXXX</copyright>
        <dependencies>
            <group>
                <dependency id="Dependency1" version="1.0.0" />
            </group>
            <group targetFramework=".NETFramework3.5">
                <dependency id="Dependency2" version="3.9.71" />
            </group>
            <group targetFramework=".NETFramework4.0">
                <dependency id="Dependency3" version="4.0.30" />
                <dependency id="Dependency4" version="4.0.30" />
                <dependency id="Dependency5" version="4.0.30" />
                <dependency id="Dependency6" version="4.0.30" />
            </group>
        </dependencies>
    </metadata>
    <files>
        <file src=".XXX.Net35\bin\Release\XXX.dll" target="lib\net35" />
    </files>
</package>

When I package the NuGet package with the nuspec via:

nuget pack XXXXXX.nuspec

Everything is good, the dependency groups are all there. If I package with the csproj like:

nuget pack XXXXXX.csproj

The dependencies are all lumped into one target rather than in groups. I really want the functionality of using the $id$ and $version$ variables with the ability to do dependency groups based on target framework.

Anyone know of a solution?

like image 836
Jonathon Cwik Avatar asked Aug 28 '14 19:08

Jonathon Cwik


1 Answers

Make sure that you go to the directory that has your .csproj file and execute nuget spec to create a .nuspec file based on your .csproj. Investigate it and make sure it looks as you want, customize it for various target frameworks, then nuget pack XXXXXX.csproj to have it build and respect the .nuspec.

like image 185
Haney Avatar answered Sep 23 '22 15:09

Haney