GitVersion icon indicating copy to clipboard operation
GitVersion copied to clipboard

Problem using nuget pack -includedependencies with assemblies using GFV

Open JustinThirkell opened this issue 12 years ago • 13 comments

Background

I have two assemblies in a solution, AssemblyA and AssemblyB. AssemblyB has a project reference to AssemblyA. I'm using GFV and publishing develop branch nuget packages from TC for both assemblies.

I end up with the following for both assemblies (from the temp AssemblyInfo written out by GFV: [assembly: AssemblyVersion("2.8.0")] [assembly: AssemblyFileVersion("2.8.0")] [assembly: AssemblyInformationalVersion("2.8.0-unstable12 Branch:'develop' Sha:'c415f7a3dbadad7b72c8af4b7ae8993d1ef35710'")] The actual compiled assemblies both have AssemblyVersion 2.8.0 .0 (I guess this is a standard .net thing - to append ".0" to get a four part version number.) When running nuget pack I'm using %GitFlowVersion.NugetVersion% as the package version and I'm telling nuget to IncludeReferencedProjects - so AssemblyB.nupkg will have a dependency on AssemblyA.nupkg

Problem

When I install AssemblyB.nupkg nuget fails to resolve the AssemblyA.nupkg dependency.

Unable to resolve dependency 'AssemblyA (= 2.8.0.0)'.

And that's because the AssemblyB nupkg contains the following:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
    <metadata>
        <id>AssemblyB</id>
        <version>2.8.0-Unstable0012</version>
        <dependencies>
            <dependency id="AssemblyA" version="2.8.0.0" />
        </dependencies>
    </metadata>
</package>

What I really want is the dependency to specify the GitFlowVersion.NugetVersion instead of the assemblyversion from the referenced project. A workaround is not to includereferencedprojects when packing but I don't want that.

How does NServiceBus handle this? How do you get your unstable NServiceBus.Host package to depend on NServiceBus? eg

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
    <metadata>
        <id>NServiceBus.Host</id>
        <version>4.0.0-unstable3109</version>
        <title>NServiceBus Host (unstable)</title>
        <dependencies>
            <dependency id="NServiceBus" version="[4.0.0-unstable3109]" />
        </dependencies>
    </metadata>
</package>

Are you munging the nuspec before you pack?

JustinThirkell avatar Jan 23 '14 20:01 JustinThirkell

Since we use ripple we lean on the update dependencies feature of create-packages

http://darthfubumvc.github.io/ripple/commands/createpackages/

It works brilliantly for us

andreasohlund avatar Jan 23 '14 20:01 andreasohlund

ah, right. started a spike ealier this week for ripple-ising our main solution here, another good reason to use it... :wink: thanks, makes sense.

JustinThirkell avatar Jan 23 '14 21:01 JustinThirkell

From the looks of it, this issue can be closed.

Reopen or post a comment if this is not the case

JakeGinnivan avatar Mar 21 '14 20:03 JakeGinnivan

Just for future reference, if you add an AssemblyInformationalVersion to your projects AssemblyInfo.cs, your package versions should be correct when doing nuget pack. (just had this exact same problem and eventually found the AssemblyInformationalVersion)

pms1969 avatar Jun 17 '15 10:06 pms1969

This problem still exists. AssemblyInformationalVersion needs to be set to NuGetVersion (e.g. 1.2.3-unstable0004) instead of the longer version with the SHA in it. Otherwise, NuGet doesn't set the dependency properly in the creation (as described in the original post).

Really need to be able to specify/override what goes into AssemblyInformationalVersion so that we can make this work.

MarkZuber avatar Oct 02 '15 01:10 MarkZuber

From nuget docs (https://docs.nuget.org/create/versioning)

If building a package from a project (.csproj or .vbproj), use the AssemblyInformationalVersionAttribute to specify the version.

[assembly: AssemblyInformationalVersion("1.0.1-alpha")]

NuGet will pick up this value instead of the one specified in the AssemblyVersion attribute (this attribute does not support SemVer which is why a different attribute was needed).

MarkZuber avatar Oct 02 '15 01:10 MarkZuber

Makes sense, thanks for clarifying.

JakeGinnivan avatar Oct 02 '15 01:10 JakeGinnivan

Happy to guinea pig a fix to this. I've been digging through the code, but not sure the best way to wire this in. Maybe something in the yaml config? or a command line parameter?

MarkZuber avatar Oct 02 '15 01:10 MarkZuber

Seeing as it is solution specific I think the yml file is a better idea. Not sure the best approach. Maybe some sort of string interpolation which you can use variables gitversion generates. I thought we had something in there but don't have time to look into it right now

JakeGinnivan avatar Oct 02 '15 02:10 JakeGinnivan

I was thinking something similar to how it's wired up for the assembly version property where you can specify in the yml: Major, MajorMinor, MajorMinorPatch, etc. Have a similar config property for assemblyfileversioninfo-format whre you can say "gitversion" or "fullinfoversion" or something like that...

MarkZuber avatar Oct 02 '15 02:10 MarkZuber

I just sent a Pull Request for this to GitTools/Master with some additional unit tests. would be interested for you to take a look at the approach when you get time.

https://github.com/GitTools/GitVersion/pull/658

thanks! mark

MarkZuber avatar Oct 02 '15 03:10 MarkZuber

This is fixed by #660 right?

Am closing this, if thats not the case then let me know @MarkZuber

JakeGinnivan avatar Jan 19 '16 09:01 JakeGinnivan

Yes. It's fixed by that cl. Thanks!

Sent from the internets.

On Jan 19, 2016, at 1:46 AM, Jake Ginnivan [email protected] wrote:

This is fixed by #660 right?

Am closing this, if thats not the case then let me know @MarkZuber

— Reply to this email directly or view it on GitHub.

MarkZuber avatar Jan 19 '16 14:01 MarkZuber