1

I am manually pushing nuget packages to Azure Devops feed by running nuget.exe push command. When I build my project, the AssemblyName.1.0.0.nupkg file is created and I am pushing it as:

nuget.exe push -Source URL -ApiKey key ..\AssemblyName.1.0.0.nupkg

This works fine and the package is published successfully (as package version 1.0.0). However, I am not able to publish a prerelease package like 1.0.0-beta.

What I tried?

  1. I added the following in AssemblyInfo.cs:
[assembly: AssemblyInformationalVersion("1.0.0-beta")]

When I build the project, it still generates AssemblyName.1.0.0.nupkg but not AssemblyName.1.0.0-beta.nupkg.

  1. I added the following in csproj:
<PropertyGroup>
    <PackageVersion>1.0.0-beta</PackageVersion>
</PropertyGroup>

Still it generates only AssemblyName.1.0.0.nupkg.

What I want?

Could you let me know how to publish a prerelease nuget package like 1.0.0-beta please?

EDIT:

The project's target framework is .NET Framework 4.5.

MAK
  • 1,915
  • 4
  • 20
  • 44
  • 1
    I would suggest using the `` MSBuild property instead of ``. That's what I've done consistently and it's fine. (I'd also suggest `1.0.0-beta-1` instead of `1.0.0-beta`, in case you need multiple beta releases, but that's a different matter.) – Jon Skeet Sep 19 '20 at 18:25
  • 1
    If you think there's going to be more than 9 betas, it's best to use `1.0.0-beta.1` to comply with the SemVer2 spec, and therefore NuGet's version sorting :) – zivkan Sep 19 '20 at 19:35
  • @Jon Skeet @zivkan I added `1.0.0-beta.1` in `csproj` but still only `AssemblyName.1.0.0.nupkg` is generated when I build the project (not `AssemblyName.1.0.0-beta.1.nupkg`). I am using `.NET Framework 4.5`. – MAK Sep 20 '20 at 01:33

1 Answers1

1

Use <Version> element in the project file and it should work!

Anand Gaurav
  • 224
  • 1
  • 4
  • I added `1.0.0-beta.1` in `csproj` but still only `AssemblyName.1.0.0.nupkg` is generated when I build the project (not `AssemblyName.1.0.0-beta.1.nupkg`). I am using `.NET Framework 4.5`. – MAK Sep 20 '20 at 01:34
  • 1
    @MAK: And you definitely reran `dotnet pack`? It really should work fine... – Jon Skeet Sep 20 '20 at 07:11
  • @JonSkeet: I am able to pack and publish the nuget package as follows: `nuget.exe pack ..\AssemblyName.nuspec -Version 1.0.0-beta.1` and then `nuget.exe push -Source URL -ApiKey az AssemblyName.1.0.0-beta.1.nupkg` After this, I see the package `1.0.0-beta.1` in VSTS Feed. I am able to do the above without adding `` tag in `csproj`. – MAK Sep 20 '20 at 09:12
  • 2
    @MAK: I didn't realize you were using a nuspec file. I strongly suggest using an SDK-style project, and just `dotnet pack`. – Jon Skeet Sep 20 '20 at 21:46