你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
通过虚拟机服务目录模板安装应用程序。
应用程序安装脚本支持以下方案:
- RemoteApp 应用安装的最常见用例是部署可从 Azure Virtual Destop 访问的远程应用程序。
- 安装先决条件,例如网络安全和监控智能体。
- 用于合规或应用程序设置的脚本配置更改。
注释
此示例部署仅用于演示目的,并不表示网络、系统或应用程序管理的所有最佳做法。
先决条件
RemoteApp 模板支持脚本,以自动执行安装应用程序和配置虚拟机的过程。 在开始使用 RemoteApp 应用安装之前,需要确保具备:
- 社区、enclave、工作负荷以及至少一个工作负荷资源组和权限,用于在工作负荷资源组中创建资源。
- 为 enclave 启用
Advanced维护模式,以便可以将专用链接资源添加到 enclave 托管资源组。 - 存储账户中的容器(构件)。
- 到存储帐户的社区终结点,以及可选的 AzCopy.exe 现有副本。
- AzCopy.exe 的副本
- 下载 AzCopy。
- 将AzCopy安装程序上传到与应用文件夹相同的级别的存储帐户。
- 文件结构:
- storage account - artifacts container - app folder - azcopy.exe
- 先前创建的社区端点与隔离区子网之间的隔离区连接
注释
如果存储帐户位于不同的 enclave 中,请使用存储帐户在 enclave 中创建 enclave 终结点 。 然后,在该存储帐户的 enclave 与要安装应用程序的 enclave 之间创建enclave 连接。
已部署的 Azure 资源
- RemoteApp 示例虚拟机
- Disk
- Windows虚拟机
- Windows虚拟机扩展
已部署的软件
- Windows操作系统
- 选择的应用程序
安装
设置存储帐户以安装Visual Studio Code
- 将应用文件夹添加到存储帐户中的容器。
- 文件结构:
- artifacts container - app folder - app installer - main script to install app - (optional) additional scripts - (optional) azcopy.exe
- 文件结构:
- 下载所需的应用程序安装程序。 在此示例中,下载 Vscode.exe 并将安装程序上传到存储帐户应用文件夹中。
- 上传与您添加到存储帐户应用文件夹中的 Visual Studio Code 版本兼容的
main.ps1应用程序安装程序脚本:# Main powershell script that installs the application Start-Process 'C:/vscode/VSCodeSetup-x64-{version}.exe' -Argument "/VERYSILENT /MERGETASKS=!runcode"
配置模板
- 在工作负荷概述页上,选择
+Add an Azure Service。
- 对于
Service,请选择Virtual Machine。
确认资源组选择并选择
Next“基本信息”选项卡:
- 对于
Virtual Machine name,输入虚拟机的名称。 - 对于
Admin username和Admin password,输入用于登录到虚拟机的用户名和密码。
- 对于
应用选项卡:
对于
App folder URI,输入容器的 URI。 选择容器中的项目,复制其 URI,删除 URI 中的文件夹名称之后 的所有内容 。
原始 URI 固定的 URI <storage-account>https://.blob.core.windows.net/<container-name>/<folder-name>/<script>.ps1<storage-account>https://.blob.core.windows.net/<container-name>/<folder-name>例:
- storageaccountexample.blob.core.windows.net/artifacts/vscode
输入
Main Script安装应用程序的脚本的名称(例如:main.ps1) 。
专用容器:
对于
App folder in private container,请选择true,以允许reader角色通过虚拟机访问存储帐户。对于
Storage container resource id,获取以下三个部分:<storage-account-resource-id>+ '/blobServices/default/containers/' +<container-name>。- 若要从存储帐户中获取
Storage container resource id,请选择“概述”,选择极右角的“JSON 视图”,复制存储帐户资源 ID。
- 对于容器名称,复制保存项目的专用容器的名称。
- 存储容器资源 ID 示例:
subscriptions/000000a0-a0a0-000a-00a0-0000aaa0a000/resourceGroups/providers/Microsoft.Storage/storageAccounts/storage-account-example/blobServices/default/containers/container-name
- 若要从存储帐户中获取
如果显示参数
AzCopy File URI,请将 azcopy.exe 的 URI 添加到容器中- 选择该文件,并复制其 URL:
专用容器参数示例:
- 选择
Review and Create,如果验证通过,请选择Create。 - 部署资源后,通过连接到应用程序虚拟机来检查应用是否已安装在应用程序虚拟机上。 连接到应用程序虚拟机
WinGet 安装
文件夹结构:
- artifacts container
- WinGet app folder ('winget')
- WinGet installer ('Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle')
- Windows UI Library ('Microsoft.UI.Xaml.2.8.x64.appx')
- main script to schedule install ('main.ps1')
- script to install and schedule reboot('install_winget.ps1')
- ('restart.ps1')
- 下载安装程序并将其上传到存储容器中的 winget 文件夹
- WinGet
MSIX捆绑包 (Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle) - Windows UI 库 (Microsoft.UI.Xaml.2.8.x64.appx)
- WinGet
- 创建和上传脚本
- main.ps1
# This script creates and runs a scheduled task to install the appx package and msix bundle with elevated privileges $installScriptPath = "C:\winget\install_winget.ps1" # Create a scheduled task action to run the installation script with elevated permissions $taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy Bypass -File $installScriptPath" # Set the task to start 30 seconds from now $taskTrigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(30) $taskPrincipal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest # Register the scheduled task Register-ScheduledTask -TaskName "InstallWinget" -Action $taskAction -Trigger $taskTrigger -Principal $taskPrincipal - install_winget.ps1
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force Start-Process -FilePath "DISM.exe" -ArgumentList "/Online /Add-ProvisionedAppxPackage /PackagePath:C:\winget\Microsoft.UI.Xaml.2.8.x64.appx /SkipLicense" -NoNewWindow -Wait Start-Process -FilePath "DISM.exe" -ArgumentList "/Online /Add-ProvisionedAppxPackage /PackagePath:C:\winget\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle /SkipLicense" -NoNewWindow -Wait $wingetDir = 'C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.23.1791.0_x64__8wekyb3d8bbwe' $currentPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) [System.Environment]::SetEnvironmentVariable("Path", "$currentPath;$wingetDir", [System.EnvironmentVariableTarget]::Machine) # Schedule the reboot script $rebootScriptPath = "C:\winget\reboot.ps1" $taskAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument "-ExecutionPolicy Bypass -File $rebootScriptPath" # Set the task to start 30 seconds from now $taskTrigger = New-ScheduledTaskTrigger -Once -At ((Get-Date).AddSeconds(30)) $taskPrincipal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest # Register the scheduled task Register-ScheduledTask -TaskName "Reboot" -Action $taskAction -Trigger $taskTrigger -Principal $taskPrincipal - restart.ps1
Restart-Computer -Force
- main.ps1
- 继续 部署模板