Azure Pipeline - Increment build number and display in web app

独自空忆成欢 提交于 2020-08-24 11:08:39

问题


I have the following simple build pipeline working in Azure DevOps with releases deployed to a staging slot.

I would like to have a build revision/version string and that is auto-incremented. I then want to display this in my web app so I can tell which version of the software is in production.

Currently I display the version string from the .csproj file. Something like this in a

<Version>1.1.4.7</Version>

And then displayed on a web page using the following code:

Version: @typeof(Startup).Assembly.GetName().Version.ToString()

If I can update the existing version string that would be great but I'm open to changing to whatever's easiest to integrate in the CI process.


回答1:


Versioning has been simplified in the .Net Core world.

Edit your csproj and modify it as follows:

<PropertyGroup>
  <Version Condition=" '$(BUILD_BUILDNUMBER)' == '' ">1.0.0.0</Version>
  <Version Condition=" '$(BUILD_BUILDNUMBER)' != '' ">$(BUILD_BUILDNUMBER)</Version>
</PropertyGroup>

If your file doesn’t have a version node, add the above.

The above setup will mean debugging locally will give you a version of 1.0.0.0, and in the event, you build in a non-Azure DevOps environment you will also end up with a 1.0.0.0 version. $(BUILD_BUILDNUMBER) is an environment variable set by Team Build and which will be updated at build time by VSTS or TFS.

The .Net version needs to be in the format [major].[minor].[build].[revision] with each segment being a number between 0 and 65000. You can configure the build number format in the Options tab, see here more info about the formatting. See here for helpful steps on configuring the build.




回答2:


You should Use Azure DevOps Pipelines Release (a.k.a. Azure Pipelines release) instead of Azure DevOps Pipelines build (a.k.a. Azure Pipelines build). Azure Pipelines release by default will auto-increment your releases.

Azure Pipelines build has no automatic version numbering by default. Because increasing version after it should be done at release stage, because build should only concerns the continuous integrations, not to be used as versioning a build to be released.

This is the official docs of Azure Pipelines release on auto-increment your release: https://docs.microsoft.com/en-us/azure/devops/pipelines/release/?view=vsts#numbering



来源:https://stackoverflow.com/questions/53735441/azure-pipeline-increment-build-number-and-display-in-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!