简体   繁体   English

Tfs build agent文件夹中众多NuGet.exe版本背后的原因是什么?

[英]What is the reason behind the multitude of NuGet.exe versions within the Tfs build agent folder?

I am grappling to understand how Tfs's VNext build handles NuGet.exe versions under the hood. 我正在努力了解Tfs的VNext版本如何在后台处理NuGet.exe版本。

I am running a Tfs 2018 (16.122.27102.1) on-prem server. 我正在运行Tfs 2018(16.122.27102.1)本地服务器。 My agent is running (as a windows service) on my machine on the location “C:\\dev\\tfs_bld_agents\\scully\\” 我的代理在计算机上的“ C:\\ dev \\ tfs_bld_agents \\ scully \\”位置(作为Windows服务)运行

If I understand it correctly the “Nuget tool installer” (1) will ensure that the NuGet.exe version specified in the build task (in this case 4.3.0), will be installed where this build definition is executed by an agent. 如果我对它的理解正确,那么“ Nuget工具安装程序”(1)将确保在由代理执行此构建定义的位置安装在构建任务(在本例中为4.3.0)中指定的NuGet.exe版本。

在此处输入图片说明

The subsequent build task “NuGet Restore”(2) will then run the NuGet.exe installed by the previous build task(1) and will execute the NuGet restore command. 随后的后续构建任务“ NuGet Restore”(2)将运行由先前构建任务(1)安装的NuGet.exe,并将执行NuGet restore命令。

在此处输入图片说明

If, however, I search through the build agent's root folder on disk “C:\\dev\\tfs_bld_agents\\scully\\” I find an array of different versions of NuGet.exe 但是,如果我在磁盘“ C:\\ dev \\ tfs_bld_agents \\ scully \\”上搜索构建代理的根文件夹,则会找到一系列不同版本的NuGet.exe。

  • 3.3.0 3.3.0
  • 3.5.0 3.5.0
  • 4.0.0 4.0.0
  • 4.3.0 4.3.0

Directories, where a version of NuGet.exe resides, are: NuGet.exe版本所在的目录为: 在此处输入图片说明

What is the reason for this behaviour ie having all these different versions within the build agent folder, seeing that the NuGet.exe version specified by my build definition was only version 4.3.0? 出现此行为的原因是什么,即在构建代理文件夹中包含所有这些不同版本,并且看到由我的构建定义指定的NuGet.exe版本仅为4.3.0版本?

Assuming that we for instance do not (or cannot in older Tfs versions) run the “NuGet Tool Installer” build task, how will the Tfs build agent go about figuring out where to find a NuGet.exe on the machine? 假设我们例如不(或不能在较旧的Tfs版本中)运行“ NuGet Tool Installer”构建任务,那么Tfs构建代理将如何确定在计算机上的哪里找到NuGet.exe?

These NuGet.exe versions are included in the NuGet Tool Installer task and NuGet task by default. 默认情况下,这些NuGet.exe版本包含在NuGet Tool Installer任务和NuGet任务中。 When you queue a build, build agent downloads the tasks build needs, then you will see these NuGet.exe versions. 在对构建进行排队时,构建代理会下载构建所需的任务,然后您将看到这些NuGet.exe版本。

So I performed some tests attempting to track what happens when you use different versions of NuGet within the “Nuget tool installer” Tfs build task. 因此,我进行了一些测试,以尝试跟踪在“ Nuget工具安装程序” Tfs构建任务中使用不同版本的NuGet时发生的情况。 For the baseline, a Tfs2018 (16.122.27102.1) build agent (of type service) was used, just extracted and configured. 对于基线,使用了Tfs2018(16.122.27102.1)构建代理(类型服务),只需将其提取并配置即可。

After configuring the build agent, you will have the following NuGet.exe in your agent directory: NuGet.exe version: 3.3.0 (3.3.0.0212) - Note: this is just after the agent was configured, no builds have been run here! 配置生成代理后,您的代理目录中将包含以下NuGet.exe:NuGet.exe版本:3.3.0(3.3.0.0212)-注意:这是在配置代理之后,此处未运行任何生成!

在此处输入图片说明

I then proceeded to set up a build definition that will be executed by agent mulder. 然后,我继续设置将由Agent mulder执行的构建定义。 The build definition contained the “NuGet Tool Installer” build task. 构建定义包含“ NuGet工具安装程序”构建任务。 My first try was to specify NuGet 2.8.6 and then run the “NuGet Tool Installer” build task. 我的第一个尝试是指定NuGet 2.8.6,然后运行“ NuGet工具安装程序”构建任务。

After this task was completed, we find the following NuGet.exe artifacts within our build agent folder: 完成此任务后,我们会在构建代理文件夹中找到以下NuGet.exe工件:

  • NuGetInstaller NuGet安装程序
  • NuGetToolInstaller NuGetToolInstaller
  • As well as the NuGet version we requested, provided on location ...\\_tool\\NuGet\\2.8.6\\x64\\nuget.exe 以及我们要求的NuGet版本,位于位置... \\ _ tool \\ NuGet \\ 2.8.6 \\ x64 \\ nuget.exe

在此处输入图片说明

From this point onwards, the content of the ...\\_tasks\\ folder seems to remain constant in regards to NuGet.exe versions, regardless of which version you specify. 从现在开始,就您指定的版本而言,就NuGet.exe版本而言,... \\ _ tasks \\文件夹的内容似乎保持不变。

The only obvious change being, the addition of every new version you select within this location ...\\_tool\\NuGet\\{version requested}\\x64\\nuget.exe. 唯一明显的变化是,在此位置... \\ _ tool \\ NuGet \\ {请求的版本} \\ x64 \\ nuget.exe中添加了每个新版本。 So if we painstakingly select each possible version in the “NuGet Tool Installer” build task and run it, we will end up with a spread that looks like this: 因此,如果我们在“ NuGet工具安装程序”构建任务中精心选择每个可能的版本并运行它,我们将最终得到如下所示的扩展:

在此处输入图片说明

Regarding the logging produced by the agent running the “NuGet Tool Installer” build task, the thing that stands out is the fact that after each switch in the NuGet version, the following message appears: Prepending PATH environment variable . 关于由运行“ NuGet工具安装程序”构建任务的代理产生的日志记录,引人注目的是在NuGet版本中的每次切换之后,都会显示以下消息: 前置PATH环境变量 I assume the purpose being to point to the selected NuGet.exe version on disk. 我假设目的是指向磁盘上选定的NuGet.exe版本。 In the case of version 2.8.6 we see the following: 对于版本2.8.6,我们看到以下内容:

Prepending PATH environment variable with directory: C:\TfsBuild\mulder\_work\_tool\NuGet\2.8.6\x64

So what happens if we revert back to a specific version? 那么,如果我们还原到特定版本会发生什么? Let say from v4.5.1 to v2.8.6 - does it clean up some versions? 假设从v4.5.1到v2.8.6-是否清理某些版本? No. It leaves everything intact but does modify the PATH variable again to point to the correct version you reverted to. 不会。它会保留所有内容,但会再次修改PATH变量以指向您还原到的正确版本。

Prepending PATH environment variable with directory: C:\TfsBuild\mulder\_work\_tool\NuGet\2.8.6\x64

An interesting phenomenon is that you cannot see these "Prepending" changes in your PATH environment variable. 一个有趣的现象是您在PATH环境变量中看不到这些“正在执行”的更改。 If you, however, run the build in debug (by flipping the system.debug variable to true) you see some interesting details. 但是,如果您运行内置调试(通过将system.debug变量翻转为true),则会看到一些有趣的细节。 This time around I can see that the variable(s) are indeed slipped in front of the existing PATH variables (that are visible in the environment variables GUI), as well as 2 more at the end. 这次,我可以看到变量确实在现有PATH变量(在环境变量GUI中可见)的前面,以及最后两个。

Debug logging looks something like this: 调试日志记录如下所示:

Prepending PATH environment variable with directory: C:\TfsBuild\mulder\_work\_tool\NuGet\2.8.6\x64
new Path: 
C:\TfsBuild\mulder\_work\_tool\NuGet\2.8.6\x64;
C:\TfsBuild\mulder\externals\git\cmd; 
.
..
<The existing paths variables>
..
.
C:\TfsBuild\mulder\bin;
C:\TfsBuild\mulder\bin

It thus seems to retrieve the existing PATH environment variable, and then slot in the “new” required variables in front of them while running the build. 因此,它似乎是检索现有的PATH环境变量,然后在运行构建时将“新的”必需变量插入它们的前面。

Clearly Tfs build is very good at ensuring that there is always a correct version of NuGet.exe at hand, but cleaning up old versions is not its strong suit :-) 显然,Tfs构建非常擅长确保始终有正确版本的NuGet.exe,但是清理旧版本并不是它的强项:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM