自动版本管理和 CHANGELOG 生成,支持 dotnet 的 semver 和传统提交
stop using weird build scripts to increment your nuget's version, use
versionize!
Automatic versioning and CHANGELOG generation, using conventional commit messages.
how it works:
main branch, select the Squash and Merge option (not required).git checkout main; git pull origin mainversionizegit push --follow-tags origin maindotnet packdotnet nuget pushversionize does the following:
.csproj file (based on your commit history).csproj file and CHANGELOG.mddotnet tool install --global Versionize…Example:
versionize --workingDir ./src init --singleEvery commit should be in the form
[optional scope]:
for example
fix(parser): remove colon from type and scope
Breaking changes must contain a line prefixed with BREAKING CHANGE: to allow versionize recognizing a breaking change. Breaking changes can use any commit type.
Example
git commit -m "chore: update dependencies" -m "BREAKING CHANGE: this will likely break the interface"versionize supports custom commit header patterns for parsing commit messages. This is particularly useful when your team uses commit messages that differ from the conventional commits format.
To configure custom header patterns, create a .versionize file in your working directory with the following structure:
{
"CommitParser": {
"HeaderPatterns": [
"^Merged PR \\d+: (?\\w*)(?:\\((?.*)\\))?(?!)?: (?.*)$",
"^Pull Request \\d+: (?\\w*)(?:\\((?.*)\\))?(?!)?: (?.*)$"
]
}
}If your team commits include messages like the following:
Merged PR 123: fix(squash-azure-case): subject text #64Pull Request 11792: feat(azure-case): subject textYou can use the above configuration to ensure these commit messages are parsed correctly. versionize will extract the relevant type, scope, and subject information to include them in the changelog and determine version increments.
Create a new project with the dotnet cli
mkdir SomeProject
dotnet new classlibEnsure that a <Version> element is contained in file SomeProject.csproj
1.0.0
Now let's start committing and releasing
git init
...make some changes to "Class1.cs"
git add *
git commit -a -m "chore: initial commit"
versionizeWill add a CHANGELOG.md, add git tags and commit everything. Note that the version in SomeProject.csproj will not change since this is your first release with versionize.
...make some changes to "Class1.cs"
git commit -a -m "fix: something went wrong we need a bugfix release"
versionizeWill update CHANGELOG.md, add git tags and commit everything. Note that the version in SomeProject.csproj is now 1.0.1.
...make some changes to "Class1.cs"
git commit -a -m "feat: something really awesome coming in the next release"
versionizeWill update CHANGELOG.md, add git tags and commit everything. Note that the version in SomeProject.csproj is now 1.1.0.
...make some changes to "Class1.cs"
git commit -a -m "feat: a really cool new feature" -m "BREAKING CHANGE: the API will break. sorry"
versionizeWill update CHANGELOG.md, add git tags and commit everything. Note that the version in SomeProject.csproj is now 2.0.0 since
versionize detected a breaking change since the commit note BREAKING CHANGE was used above.
In some scenarios, you may want to bump a different version element instead of the standard `` element in your project files. This can be useful when you want to track file versions independently from package versions, or when working with specific version properties.
To use this feature, ensure your project file contains the desired version element (e.g., or):
1.0.0
Configure this in your .versionize file as part of the project configuration:
{
"projects": [
{
"name": "MyProject",
"path": ".",
"versionElement": "FileVersion"
}
]
}For single-project repositories (non-monorepos), you can also configure it at the root level:
{
"projects": [
{
"path": ".",
"versionElement": "FileVersion"
}
]
}When this option is specified, versionize will:
) instead of Supported values include Version (default), FileVersion, AssemblyVersion, or any custom property name. Only alphanumeric and underscore characters are allowed.
Versionize supports creating pre-release versions by using the --pre-release flag with a pre-release label, for example alpha.
The following workflow illustrates how pre-release workflows with versionize work.
> git commit -a -m "chore: initial commit"
> versionize
// Generates version v1.0.0
> git commit -a -m "feat: some feature"
> versionize --pre-release alpha
// Generates version v1.1.0-alpha.0
> git commit -a -m "feat: some additional feature"
> versionize --pre-release alpha
// Generates version v1.1.0-alpha.1
> git commit -a -m "feat: some breaking feature" -m "BREAKING CHANGE: This is a breaking change"
> versionize --pre-release alpha
// Generates version v2.0.0-alpha.0
> versionize
// Generates version v2.0.0By default, each commit message only appears in the release it was introduced. When using the pre-release feature this can result in a fragmented changelog. For example, when promoting to a full release the user has to browse through all the pre-release sections to see what's included.
v1.0.0-alpha.0
- featA
v1.0.0-alpha.1
- featB
v1.0.0So to get around that you can pass the --aggregate-pre-releases flag
versionize --pre-release alpha
versionize --pre-release alpha
versionize --aggregate-pre-releasesto get output like the following
v1.0.0-alpha.0
- featA
v1.0.0-alpha.1
- featB
v1.0.0
- featA
- featBThis also works together with the pre-release option
versionize --pre-release alpha --aggregate-pre-releases
Some developers may prefer not to tag pre-releases. Here's an example of how to achieve that:
versionize --pre-release alpha --skip-tag
versionize --pre-release alpha --skip-tag --find-release-commit-via-message
...find-release-commit-via-message is necessary because Versionize uses git tags by default to determine the current version. Without a git tag, the way we determine which commits get included in the changelog is by searching for the last commit message that starts with "chore(release):".
You can configure versionize either by creating a .versionize JSON file the working directory.
Any of the command line parameters accepted by versionize can be provided via configuration file leaving out any -. For example skip-dirty can be provided as skipDirty in the configuration file.
The .versionize configuration file is deserialized into a FileConfig.cs object behind the scenes.
You can also extend a shared configuration file using extends. The value can be a URL or a local file path. Local values override the extended config.
{
"extends": "https://example.com/shared/.versionize",
"skipDirty": true
}Changelog customization can only be done via a .versionize file. The following is an example configuration:
…Because includeAllCommits is true and the fix section is hidden, fix commits will appear in a section titled "Miscellaneous" (as specified by otherSection). If otherSection is not specified, it defaults to "Other".
You can customize the links generated in the changelog using the linkTemplates configuration. The following placeholders are supported:
{issue} - Issue number (e.g., 123){commitSha} - Full commit SHA{currentTag} - Current version tag (e.g., v1.2.3){previousTag} - Previous version tag (e.g., v1.2.2)The {currentTag} and {previousTag} placeholders are particularly useful for creating compare links that show all changes between releases:
{
"changelog": {
"linkTemplates": {
"versionTagLink": "https://github.com/versionize/versionize/compare/{previousTag}...{currentTag}"
}
}
}This will generate links like: https://github.com/versionize/versionize/compare/v1.9.0...v1.10.0
You can add an opt-in Thank You section at the bottom of each changelog entry that lists the authors who contributed commits in that release. For public GitHub and GitLab repositories the author's username is resolved automatically; for other hosts, or private repositories, only the author name is shown.
Enable it in your .versionize file:
{
"changelog": {
"includeAuthors": true
}
}You can also customise the section heading:
{
"changelog": {
"includeAuthors": true,
"authorsSection": "Contributors"
}
}This produces a section like:
### Thank You
* Alice Smith @alicesmith
* Bob Jones @bobjones
* Steven NanceAuthors are deduplicated by email and listed alphabetically. GitHub usernames are resolved via the GitHub commit API; GitLab usernames are resolved via the GitLab GraphQL API. Username resolution is only supported for public repositories — if username resolution fails or the repository is private or hosted elsewhere, only the author name is displayed.
Want to do a PR and not care about setting up your development environment?
To get prettier test outputs run dotnet test with prettier test logger
dotnet test --logger prettier暂无开放 Issues,或尚未同步最近议题。