Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the dotnet-pack --version-suffix with csproj?

Tags:

I'm trying to use the .net Core tools RC4 dotnet pack command to create a nuget package with a suffix.

I can create "MyProject.1.2.3.nupkg" successfully but I want "MyProject.1.2.3-beta.nupkg".

According to the documentation here the --version-suffix "Updates the star in -* package version suffix with a specified string."

I've managed to find where dotnet pack is getting it's version from - dotnet pack uses msbuild under the covers which uses the <version/> element in the csproj file. For example <version>1.2.3</version> creates a file called "MyProject.1.2.3.nupkg".

If I set the <version/> in the csproj to something like 1.2.3 and specify --version-suffix beta then it doesn't append the -beta but it does build.

If I set version to be <version>1.2.3-*</version> then dotnet restore breaks saying '1.2.3-*' is not a valid version string.

I think I'm close; what have I got wrong?

like image 241
Daniel James Bryars Avatar asked Mar 05 '17 19:03

Daniel James Bryars


People also ask

What is dotnet pack?

The dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package (that is, a . nupkg file).

What is the difference between the dotnet pack and dotnet publish commands?

dotnet pack : The output is a package that is meant to be reused by other projects. dotnet publish : The output is mean to be deployed / "shipped" - it is not a single "package file" but a directory with all the project's output.

Does dotnet build do a restore?

You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new , dotnet build , dotnet run , dotnet test , dotnet publish , and dotnet pack . To disable implicit restore, use the --no-restore option.


1 Answers

According the documentation, the Version property override the version on packing, instead, use the VersionPrefix.

<PropertyGroup>   <VersionPrefix>1.0.0</VersionPrefix> </PropertyGroup> 

And use the command to pack solution:

dotnet pack --version-suffix beta 

Optionally you can set VersionPrefix and VersionSuffix in .csproj file.

<PropertyGroup>   <VersionPrefix>1.0.0</VersionPrefix>   <VersionSuffix>alpha</VersionSuffix> </PropertyGroup> 
like image 75
Ricardo Fontana Avatar answered Sep 30 '22 19:09

Ricardo Fontana