简体   繁体   中英

How do I autoincrement the Package Version revision number when using a .Net Core format project file in VS2019

Previous answers to this question refer to editing the AssembyInfo.cs file to set the Assembly Version. I am generating a NuGet package using the new leaner .Net Core format of .csproj file for .Net Framework 4.6.1, and there is no AssemblyInfo.cs (or it's auto-generated and deleted).

If I try to set the Package Version property to 1.0.2.* in the project properties in VS2019, I get a popup error:

此字段中不允许使用通配符(“ *”)

If possible, how can I get the revision number to auto-increment, ideally so on each build the number is incremented (1.0.2.45 => 1.0.2.46) and the number is retained across releases (1.0.2.46 => 1.0.3.47, manually editing the build/release number).

Note: I've already looked at the answer here , here and here and they all refer to the AssemblyVersion attribute. I want to update the Package Version (which is simply the Version in the CSProj file).


Update: One of the answers suggested a couple of GIT versions tools. I forgot to mention that TFS is used for a lot of the projects I want to use this on; these are work projects shared with other team members and are well established so could not easily be migrated to GIT without a lot of discussion even if it didn't get a simple veto by management as an unnecessary change.

There's no auto increment support for versioning nuget packages. You need to figure out/set the version number manually (or programmatically) through something like msbuild, a continuous integration platform, or third party tool.

First, on wildcards in assembly and package versions:

The wildcard for assembly (not package) versions is discouraged from being used - the new default for "sdk-style" projects use a compiler feature called "deterministic build" which aims to produce a binary identical output for every time the same unchanged source code is compiled. This mode does not allow for wildcards in assembly versions, which would change every 2 seconds.

However, this feature can be turned off by setting

<PropertyGroup>
    <Deterministic>False</Deterministic>
</PropertyGroup>

If you then use a wildcard in your assembly version, the compiler will update your version based on the current time.

To re-use this assembly version for the package version, you need to add some additional build logic to your project file as described here: MSBuild /t:pack Nuget-Package has always the same Version

What I encourage to do:

A lot of projects use their git history for versioning, incrementing the version based on the git commit count.

I suggest looking into tools like Nerdbank.GitVersioning (lightweight and easy to use) or GitVersion (more features and better documentation) that allow you to configure how your versions can be automatically derived from the branches/tags that are being built.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM