We can trigger the GitHub Action by Git tag pushed and we can read the Git tag name as the version. And then we can generate the NuGet package with this version.
There is a dotnet tool that can read Git tags as a version and write it to the version file.
Before using it, we should create the version file and import the version file.
We should use dotnet to install the dotnetCampus.TagToVersion tool and use the tool to write the Git tag to version file.
The step 1:
Adding the Directory.Build.props
file to repo folder.
Writing the code to the Directory.Build.props
file.
The step 2:
Making a folder named build
and adding the Version.props
file to this folder.
Writing the code to the build\Version.props
file.
The step 3:
Writing a GitHub Action configuration file in .github\workflows
folder, for example create the .github\workflows\push tag and pack nuget.yml
file
Making the Action trigger by tag push.
Writing the tag as version by dotnet tool.
Building the package
See https://github.com/dotnet-campus/dotnetCampus.TagToVersion
原文链接: http://blog.lindexi.com/post/How-to-generate-NuGet-package-with-Git-Tag-version-using-GitHub-Action
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。 欢迎转载、使用、重新发布,但务必保留文章署名 林德熙 (包含链接: https://blog.lindexi.com ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我 联系。