lerp90
lerp90

Reputation: 531

nuget: package version is not being updated

I'm trying to pack a new version of a custom NuGet package and when I use the pack command I'm getting a .nupkg file which has a version number that doesn't match with the one that I've specified in the .nuspec file.

Example:

nuget pack mypackage.csproj -IncludeReferencedProjects -Prop Configuration=Release

.nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>mypackage</id>
    <version>1.0.1</version>
    <authors>me</authors>
    <owners>me</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>blah</description>
    <releaseNotes></releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>tag1 tag2</tags>
    <dependencies>
    </dependencies>
  </metadata>
</package>

I should get a file named mypackage.1.0.1.nupkg, but I'm getting a file named mypackage.1.0.0.nupkg instead

I'm also getting the same result when I try to pack it by using the AssemblyInfo data included in the Properties\AssemblyInfo.cs and declaring the version as a variable in the .nuspec file:

Properties\AssemblyInfo.cs ... [assembly: AssemblyVersion("1.0.1")] ...

Should I look for another properties in my project to update my NuGet package?

SOLUTION: Ignored the .nuspec file and managed the package versions via .csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net451;net452</TargetFrameworks>
    ...
    <AssemblyVersion>1.2.1</AssemblyVersion>
</Project>

Thanks in advance!

Upvotes: 3

Views: 4558

Answers (3)

DJD
DJD

Reputation: 226

  1. Make sure to change both the Assembly Version and File Version in Project Properties > Application > Assembly Information. In Visual Studio 2022, change Package Version in Project Properties > Package > General
  2. After that make sure you are set to Release mode and build your project.
  3. Execute the Nuget Spec command in your project's folder
  4. Edit the Spec, version should be set to $version$ so as to grab it from your project, remove the lines that need removing, fill the ones with placeholders.
  5. Execute your Nuget Pack command in the same folder and you should be good.

I often forget to build my project so it doesn't update the version.

Upvotes: 1

lerp90
lerp90

Reputation: 531

Well, I've finally managed to update my version by packing using the AssemblyInfo version. It seems like my publishing process for this package is completely ignoring the .nuspec file and gets the version from the last compiled source.

Upvotes: -1

Simply Ged
Simply Ged

Reputation: 8642

I fell foul of this recent as well. You need to use the Properties\AssemblyFileVersion attribute to set the correct value for a nuget package

[assembly: AssemblyFileVersion("1.0.1")]

Upvotes: -1

Related Questions