I have a C# solution containing a single project and multiple libraries using .Net 6. I'm using conventional commits (commitlint with husky) and want to use semantic-release to deploy the latest build as a ZIP file on Github based on the commit messages.
The setup I tried for C# projects:
- Install packages
.
npm install semantic-release -D
npm install @semantic-release/changelog -D
npm install @semantic-release/npm -D
npm install @semantic-release/github -D
npm install @semantic-release/git -D
- Create a .releaserc.json file inside the root directory
.
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/github",
{
"assets": [
{
"path": "my-project.zip",
"label": "my-project-${nextRelease.gitTag}.zip",
"name": "my-project-${nextRelease.gitTag}.zip"
}
]
}
],
"@semantic-release/git"
]
}
- Inside the package.json file set the key
version
to0.0.0-development
, set the keyprivate
totrue
and add a repository url - Create a release-on-push-on-main-branch.yml file inside the workflows directory
.
name: Release on push on main branch
on:
push:
branches:
- main
jobs:
release-on-push-on-main-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install Node dependencies
run: npm install
- name: Setup .Net
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: Install .Net dependencies
run: dotnet restore ./SolutionDir
- name: Run build
run: dotnet build ./SolutionDir
- name: Run publish
run: dotnet publish ./SolutionDir
- name: Rename publish directory of MyProject to my-project and move it to root
run: mv ./SolutionDir/MyProject/bin/Debug/net6.0 ./my-project
- name: ZIP my-project directory
run: zip -r my-project.zip my-project
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release --branches main
It seems to work, whenever I push to the main branch it will deploy the distribution (containing the DLL) with the latest version to the Github releases.
But as you know semantic-release does not release the correct package version because it doesn't know about the assembly version yet. It takes the version from the package.json file.
What I want to achieve:
- When making changes in libraries or apps inside the solution it should automatically increase their assembly versions based on the conventional commits. But obviously just if that project was modified.
- When running the release process semantic-release should release the project with
"name": "my-project-${assembly-version}.zip"
Is there something I can use?