"dotnet publish" supports msbuild command line options like /p:Version=1.2.3.4
Please add information about it to this article as well as several examples.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
I agree that we should have some information and examples about msbuild, but we shouldn't go too deep, but the relationship should be called out. We should however link to more in depth articles about it.
I'm publishing a .NET Core 2.1 app via GitLab and this is how I state the desired version details:
bash
dotnet publish MyConsoleAppProject.csproj --configuration Release --output .my-console-app --runtime win-x86 --self-contained true /p:VersionPrefix=2.34.12 /p:VersionSuffix=rc1 /p:InformationalVersion=my-console-app-2.34.12-rc1+sha.6afh4vew.win-x86
The versioning related build properties have been set to specific values following semantic versioning guidelines (https://semver.org/):
Check this post for more info related to versioning related properties: https://andrewlock.net/version-vs-versionsuffix-vs-packageversion-what-do-they-all-mean/.
@satrapu If I may ask, how are you generating the full string my-console-app-2.34.12-rc1+sha.6afh4vew.win-x86?
@satrapu If I may ask, how are you generating the full string
my-console-app-2.34.12-rc1+sha.6afh4vew.win-x86?
I was using a script step in a GitLab pipeline (a YAML file) in conjunction with some Windows Batch and several pipeline variables to form the my-console-app-2.34.12-rc1+sha.6afh4vew.win-x86 string. The end-goal was to publish a .NET Core 2.x web application targeting Windows running on 32b bits using the self-contained deployment mechanism.
| Token | Description | Location |
| ---------------------- | ------------------ | ---------------------------------------- |
| my-console-app | Application name | Declared as a variable inside YAML file |
| 2.34.12 | Semantic version | Declared as a variable, outside YAML file |
| rc1 | Pre-release info | Declared as a variable, outside YAML file |
| 6afh4vew | The first 8 characters of the currently built Git commit hash | Computed by the pipeline at build time |
| win-x86 | RID | Declared as a variable inside YAML file |
The most interesting/hard part was extracting the first 8 characters out of the current Git commit hash (e.g. 6afh4vew) - see here how to employ Windows Batch for this task.
Unfortunately, I no longer have access to the original source code to provide more details and currently I'm not using GitLab to discover the exact solution once again.
An alternative to Windows Batch is to invoke a PowerShell script with a bunch of parameters to create the final string.
@satrapu Thank you so much for all the detail! Very useful!
@tdykstra is there anything left to do here? It looks like this is solved by #17671. The synopsis also contains some examples of msbuild property usage with specific properties that are relevant to publishing: ([-p:PublishReadyToRun=true] [-p:PublishSingleFile=true] [-p:PublishTrimmed=true])
Yes, I'll close this issue, as the examples added in #17671 show msbuild property usage.
Most helpful comment
I agree that we should have some information and examples about msbuild, but we shouldn't go too deep, but the relationship should be called out. We should however link to more in depth articles about it.