chocolatey / chocolatey/choco

Mechanism to generate .cs with package version from command line

Open
#2,192 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
11.5k
Forks
960
PR merge metrics
No merged PRs in 30d

Description

Sometimes you might want to harmonize package version with your application version - this in a turn means that choco can list existing / already published packages and generate some sort of .cs file for storing that version information in .cs file, so it can be used by application or plugin.

Example command line how .cs file could be generated:

```
>choco list PackageId --limitoutput --config Release --versionfiledir C:\Project\VersionInfo\ --versionclass MyCompany.Versioning.MyPackageVersion --baseversion 1.2.0.0 --next
MyPackageVersion.cs (1.2.0.5) was updated.
Exiting with 0
```

Which in a turn would generate file like this:
```
// This file is generated by choco, do not edit - your changes will be lost on next generation

using System;

namespace MyCompany.Versioning {
///
/// Package version information.
///
public static class MyPackageVersion {

public static readonly string PackageId = "PackageId";

public static readonly string VersionString = "1.2.0.5";
public static readonly int Major = 1;
public static readonly int Minor = 2;
public static readonly int Build = 0;
public static readonly int Revision = 5;
public static readonly Version version = new Version(Major, Minor, Build, Revision);
};
};
```

This would give a change for application to access it's own package id, for example if it wants to perform software upgrade, also current application version.

Few notes here:
This version file generation is required only for official builds, built by build machines, but not for developers - that's why I have added flag `--config $(Configuration)`, which 'Release' would force file generation, and 'Debug' would only generate file if that one does not exists.

`--versionfiledir $(ProjectDir)` would control where to output file.

`--versionclass namespace.classname` would control namespace / class name where to store results.

`--baseversion $(ConfiguredPackageVersion)` could be used to specify base application version, where A.B.C would be taken from this command line argument, but .D would be autogenerated => .D would be taken from server and additionally incremented. (`--next`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.