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

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

问题描述

我在 Azure DevOps 中使用了以下简单的构建管道,并将版本部署到暂存槽.

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.

目前我显示 .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 Pipeline - 增加内部版本号并在 Web 应用程序中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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