NuGet Packager,其版本使用内部版本号,并添加-beta [英] NuGet Packager with version using build number, adding -beta

查看:60
本文介绍了NuGet Packager,其版本使用内部版本号,并添加-beta的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是将NuGet程序包(部署到内部的Nuget服务器中)部署为基于日期和最新修订版自动增加版本,并包含-beta标记.

我正在使用VSTS来构建和打包使用Cake,其内部版本号格式为 $(BuildDefinitionName)_2.0.$(Date:yyMMdd)$(Rev:.r).我有一个.nuspec清单文件,该文件指定: $ version $ ,以及这样的NuGet Packager:

这很好.但是现在,我想选择一个NuGet打包程序,该程序生成一个标记为beta的程序包,并因此在VS NuGet程序包管理器中显示为预发布版本.如果我用在NuGet Packager中附加"-beta"的版本号进行硬编码,则可以执行以下操作:

但是如何包含-beta标记和内部版本号?我想我需要在 NuGet Arguments 中包含一个变量,该变量将返回 $(BuildDefinitionName)_2.0.$(Date:yyMMdd)$(Rev:.r)"-beta",但我不确定如何.我尝试用内部版本号格式创建一个变量(在变量选项卡下),然后在NuGet参数(-Version theVariable )中引用该变量,但收到错误,表明该变量不受支持.

这可能是我的错,但是我的搜索没有发现关于如何从日期开始自动增加版本以及包含-beta标记的任何提示.

解决方案

NuGet Packager的版本使用内部版本号,并添加-beta

我可以站在你这边重现你的情况.我认为带有内部编号的 Nuget pack 任务不支持字符或数字.您可以检查

内部版本号格式:

现在,您可以看到它运行良好:

注意:

您说您使用VSTS构建和打包使用Cake ,但是发布的图像显示您在 .如果您确定使用TFS 2015,恐怕上述解决方法对您不起作用.因为自定义nuget任务不支持TFS 2015.

希望这会有所帮助.

My goal is to deploy NuGet packages (to in-house Nuget server) that auto-increment the version based on date and last Rev, and include a -beta tag.

I am using VSTS to build and package using cake, with a build number format of $(BuildDefinitionName)_2.0.$(Date:yyMMdd)$(Rev:.r). I have a .nuspec manifest file that specifies: $version$, and a NuGet Packager as such:

This works great. But now, I want to have the option of a NuGet packager that produces a package that is tagged as beta, and therefor show in VS NuGet Package Manager as pre-release. I can do this if I hard code the version number with "-beta" appended in the NuGet Packager:

But how can I include the -beta tag AND the the build number? I think I need to include a variable in NuGet Arguments that will return $(BuildDefinitionName)_2.0.$(Date:yyMMdd)$(Rev:.r) plus "-beta", but I'm not sure how. I tried creating a variable (under the Variables tab) with the Build Number Format as the value, then referencing the variable in NuGet Arguments (-Version theVariable), but received as error that the variable is not supported.

I may be going about this all wrong, however my searches have not turned up any hints on how to auto-increment versions from the date, and include a -beta tag.

解决方案

NuGet Packager with version using build number, adding -beta

I could reproduce your scenario on my side. In my opinion, Nuget pack task with build number doesn't support character or numbers. You may check this task:

case "byBuildNumber":
                tl.debug("Getting version number from build number")

                if(tl.getVariable("SYSTEM_HOSTTYPE") === "release")
                {
                    tl.setResult(tl.TaskResult.Failed, tl.loc("Error_AutomaticallyVersionReleases"));
                    return;
                }

                let buildNumber: string =  tl.getVariable("BUILD_BUILDNUMBER");
                tl.debug(`Build number: ${buildNumber}`);

                let versionRegex = /\d+\.\d+\.\d+(?:\.\d+)?/;
                let versionMatches = buildNumber.match(versionRegex);
                if (!versionMatches)
                {
                    tl.setResult(tl.TaskResult.Failed, tl.loc("Error_NoVersionFoundInBuildNumber"));
                    return;
                }

                if (versionMatches.length > 1)
                {
                    tl.warning(tl.loc("Warning_MoreThanOneVersionInBuildNumber"))
                }

                version = versionMatches[0];
                break;

That is the reason why the field $(BuildDefinitionName) and beta could not appear in our package version when we use them in our build number.

If we specify the nuget version in the nuget arguments, but this argument could not parsing predefined variables, like $(Rev:.r).

The limitations of these two situations have caused your current issue.

The workaround to resolve this issue, is using nuget custom task with parameter -version $(Build.BuildNumber) and move the field $(BuildDefinitionName) from our Build number format, otherwise, we still receive the error the version is invalid.

So, you nuget custom looks like:

And the Build number format:

Now, you can see it works fine:

Note:

You said you using VSTS to build and package using cake, but the images you posted shows that you are using NuGet Packagertask in TFS 2015. If you are sure using TFS 2015, I am afraid above workaround will not work for you. Because the custom nuget task is not support for TFS 2015.

Hope this helps.

这篇关于NuGet Packager,其版本使用内部版本号,并添加-beta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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