Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391256

Override package version when building a Nuget package from a .NET Standard project?

I am changing a project of mine to be based on .NET Standard instead of an odd combination of portable frameworks.

Everything seems to be in order, except that when I build the release binaries and thus the .nupkg package, the version is of course the one specified in the .csproj file.

Is there a way, using msbuild on the command line or from a batch file to override this property?

Basically, if I want to build version 2.3.4.5, can I, using msbuild or environment variables (anything short of modifying project files), make the final version of the nuget package be version 2.3.4.5?

Previously I had a FinalBuilder project which I'm trying to move away from which manipulated the AssemblyInfo.cs file but this was error-prone in the sense that at least twice I managed to commit modified files into my repository. I would be much more happy with a solution which just injected the version during the build process.

This is my current msbuild command line:

msbuild DiffLib.sln /target:Clean,Rebuild /p:Configuration=Release

Upvotes: 0

Views: 1225

Answers (1)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391256

OK, so it turns out this was quite easy. I found several questions on how to hack various msbuild files to get a variable to use in the properties but as it turns out all I needed was this:

msbuild DiffLib.sln /target:Clean,Rebuild /p:Configuration=Release /p:Version=2.3.4.5
                                                                   ^----------------^

The final nuget package was thus named

DiffLib.2.3.4.5.nupkg

and the dll inside had the correct version as well.

Note that this is a .NET Standard project, so the .csproj file looks like a .nuspec file instead of the traditional .csproj file format. This may be why this is now so easy.

Upvotes: 1

Related Questions