Azure管道-递增内部版本号并在Web应用程序中显示 [英] Azure Pipeline - Increment build number and display in web app

查看:239
本文介绍了Azure管道-递增内部版本号并在Web应用程序中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Azure DevOps中使用以下简单的构建管道,并将发行版部署到临时插槽.

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

我想要一个构建修订/版本字符串,并且该字符串是自动递增的.然后,我想在我的Web应用程序中显示它,以便我可以知道该软件的哪个版本正在生产中.

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.

当前,我显示.csproj文件中的版本字符串.

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()

如果我可以更新现有的版本字符串,那将是不错的选择,但我愿意更改为在CI流程中最容易集成的版本.

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.

推荐答案

.Net Core世界中的版本已得到简化.

Versioning has been simplified in the .Net Core world.

编辑您的csproj并进行如下修改:

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.

以上设置将意味着在本地调试将为您提供1.0.0.0的版本,并且在这种情况下,如果您在非Azure DevOps环境中构建,则最终也将获得1.0.0.0版本. $(BUILD_BUILDNUMBER)是Team Build设置的环境变量,将在VSTS或TFS生成时进行更新.

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.

.Net版本的格式应为[major].[minor].[build].[revision],每个段的编号介于0到65000之间.您可以在中配置内部版本号格式>选项标签,请参见这里以获取有关配置版本的有用步骤.

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.

这篇关于Azure管道-递增内部版本号并在Web应用程序中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆