Visual Studio 2019 离线布局更新忽略了 '--noUpdateInstaller' 参数。

3
我们使用{{link1:“Visual Studio离线布局”}}将VS 16.6部署到具有混合互联网连接(离线/代理/直接)的开发人员和构建服务器。直到最近,从先前的VS实例(确切地说是16.3)进行的安装/更新效果相当好。
目前,我们无法再使用离线布局来安装本地缓存版本的Visual Studio,因为连接到互联网的计算机希望在安装任何内容之前更新“Visual Studio Installer”。
调用vs_Professional.exe update --wait --norestart --noweb --noUpdateInstaller ...后很快失败并退出代码为'1'。
查看TEMP中的dd_日志,我们发现:
VisualStudio Bootstrapper:08.06.2020 10:17:49: Starting VS setup process 'vs_installer.exe' with arguments ' --layoutPath "<unc_path>\vs2019_250520_layout" --in "\<unc_path>\vs2019_250520_layout\Response.json" update --passive --norestart --productkey ;-) --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.NetCoreTools --add Microsoft.VisualStudio.Workload.Node --add Microsoft.VisualStudio.Component.VC.v141.MFC --includeOptional --includeRecommended --addProductLang en-us --locale de-DE --activityId "2e4fbc9e-37da-4791-9228-11b9649b69fa" --pipe "d549be32-ee39-49d5-b871-bed44625cafb"'.
VisualStudio Bootstrapper:08.06.2020 10:17:49: VS setup process C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe started. All done.
VisualStudio Bootstrapper:08.06.2020 10:17:49: Waiting for setup process to complete...
VisualStudio Bootstrapper:08.06.2020 10:17:54: Pipe disconnected.
VisualStudio Bootstrapper:08.06.2020 10:17:56: VS setup process exited with code 1
VisualStudio Bootstrapper:08.06.2020 10:17:56: Bootstrapper failed with client process error or unknown error.

我们在调用Visual Studio Installer时已经使用了--noweb--noUpdateInstaller标志,这让我认为这些参数没有被正确处理。
是否有一种方法可以强制使用--noUpdateInstaller,Visual Installer是否也可以在更新Visual Studio之前离线更新?

编辑:解决此问题的可能方法是确定目标工作站是否连接到互联网,如果没有连接,则根据此检查结果指定使用“--noUpdateInstaller”。

例如,在我们的部署脚本中:

$hasInternetConnection = try {
  $request = [System.Net.WebRequest]::Create( "http://microsoft.com" )
  $response = $request.GetResponse()
  $response.StatusCode -eq 200
}
catch {
  $false
}

# use '--noUpdateInstaller' iff we are not connected to the internet!
$updateInstaller = if ($hasInternetConnection) {
  ""
}
else {
  "--noUpdateInstaller"
}

$packageArgs = @{
  packageName    = $packageName
  fileType       = 'EXE'
  file           = $(Join-Path $layoutPath "vs_Professional.exe")
  softwareName   = 'Microsoft Visual Studio 2019 Professional'

  silentArgs     = "$setupPrefix --passive --norestart --wait --productkey $productKey --nocache $updateInstaller --noWeb $selectedWorkloads --includeOptional --includeRecommended --addProductLang en-us"
  validExitCodes = @(0, 3010)
}

Install-ChocolateyInstallPackage @packageArgs
2个回答

3

不幸的是,--noUpdateInstaller 参数非常误导人,并且并没有完全做到其名称所表达的意思。

Visual Studio 的“离线安装程序”只有在您的计算机没有连接到互联网时才能真正的离线工作,否则它将始终联系微软并检查更新是否可用,至少对于安装程序本身的 vs_installer.exe。如果您的计算机没有互联网连接,则需要指定 --noUpdateInstaller 来忽略无法检查更新的错误。

create-a-network-installation-of-visual-studio 上的“提示”如下:

如果要从离线源安装到未连接网络的计算机,请同时指定 --noWeb 和 --noUpdateInstaller 选项。前者可以防止下载更新的工作负载、组件等。后者可以防止安装程序从 Web 进行自我更新。

其中缺失的是如果安装程序有新版本,则命令执行将以退出代码 '1' 失败。这似乎是故意为之,但可以通过对您的安装/部署/升级脚本进行小修改来解决。


解决方法 #1 - 总是先尝试升级 vs_installer,然后使用离线布局

(用于部署 VS 到主机的示例 PowerShell 脚本,注意:vs_professional.exe 从 UNC 共享调用!)

# let the magical vs_installer be updated, if vs has already be installed previously

if (Test-IsVSAlreadyInstalled) {
  try {
    vs_professional.exe --quiet --update --wait
  } catch {
    Write-Host "failed to update magical vs_installer"
  }
}

# only pass "update" if VS is already installed
$updatePrefix = if (Test-IsVSAlreadyInstalled) { "update" } else { "" }

# install or upgrade visual studio
vs_professional.exe $updatePrefix --passive --norestart --wait --productkey $productKey --noWeb $selectedWorkloads

解决方法 #2 - 仅在未连接互联网时使用 --noUpdateInstaller

注意:此方法将允许 vs_installer.exe 更新自身,但仅使用离线布局位置中的 vsix 包和二进制文件。

(示例 PowerShell 脚本用于在主机上部署 VS,请注意:vs_professional.exe 是从 UNC 共享调用的!)

hasInternetConnection = try {
  $request = [System.Net.WebRequest]::Create( "http://microsoft.com" )
  $response = $request.GetResponse()
  $response.StatusCode -eq 200
}
catch {
  $false
}

# use '--noUpdateInstaller' iff we are not connected to the internet!
$updateInstaller = if ($hasInternetConnection) {
  ""
}
else {
  "--noUpdateInstaller"
}

# only pass "update" if VS is already installed
$updatePrefix = if (Test-IsVSAlreadyInstalled) { "update" } else { "" }

# install or upgrade visual studio
vs_professional.exe $updatePrefix --passive --norestart --wait --productkey $productKey --nocache $updateInstaller --noWeb $selectedWorkloads

我正在使用类似工作区 #2 中描述的脚本,将其包装成 Chocolatey 包,并且目前已经取得了良好的结果。

-2
每次更新vs时,你必须先更新vs_installer程序。正如你所描述的,你使用的是`vs_Professional.exe update --wait --norestart --noweb --noUpdateInstaller`,这意味着你正在更新vs_installer程序。从这里可以找到一些提示
而`--noUpdateInstaller`表示阻止更新`vs_installer.exe`。如果你执行更新操作,它将返回一个非零的退出代码。因此,你不能在更新中使用`--noUpdateInstaller`。

1) 如果您想在代理上安装旧版的VS离线包,您应该使用以下命令来安装它:(断开互联网连接)

C:\Layout\vs_Professional.exe --wait --norestart --noweb --quiet --noUpdateInstaller

2) 如果你想将 VS 离线包更新到最新版本,可以尝试以下方法:

在服务器上,找到之前创建离线安装包的程序,并使用以下命令进行更新:

vs_Professional.exe --quiet --update

然后运行以下命令以覆盖旧的 Layout 文件夹:
vs_Professional.exe --layout c:\xxx(the previous offline packages and overwrite the latest updates to this package)

或者直接运行第二个命令也可以将离线包更新到最新版本。

希望能对您有所帮助。


实际上,我想要更新现有的客户端或安装到新的客户端。如果没有vs_installer的更新可用,则我提供的命令可以正常工作,但是一旦在线发现了vs_installer的新版本,它就会失败。对于没有互联网连接的主机(升级和初始安装场景),始终可以正常工作。 - mwallner
1
您提供的资源说明如下:首先,更新Visual Studio安装程序: vs_enterprise.exe --quiet --update然后,更新Visual Studio应用程序本身: vs_enterprise.exe update --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" --quiet --wait --norestart因此,实际上“vs_enterprise update”似乎是升级VS的正确命令(根据此文档,它确实按照我预期的方式工作)。 - mwallner
1
既然您已经找到了解决问题的方法,我建议您可以添加一个答案,然后标记您的答案,以便其他社区成员搜索和处理类似的问题。 - Mr Qian
我在公司代理后面。这对我有用(将安装移动到短路径d:\vs\之后):vs_enterprise.exe --quiet --update,然后 vs_enterprise.exe update --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" --quiet --wait --norestart --noweb --force - Anton Krouglov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接