ARTICLE DETAIL

资讯详情

深耕网站视觉设计与运营推广的一线实战洞察。

Aspire CLI PR 实测指南:用 get-aspire-cli-pr 脚本 Dogfood 任意 Pull Request 的构建产物

Aspire CLI PR 实测指南:用 get-aspire-cli-pr 脚本 Dogfood 任意 Pull Request 的构建产物 Aspire CLI PR 实测指南用 get-aspire-cli-pr 脚本 Dogfood 任意 Pull Request 的构建产物【免费下载链接】aspireAspire is the tool for code-first, extensible, observable dev and deploy.项目地址: https://gitcode.com/GitHub_Trending/as/aspire本文基于 Aspire 仓库的官方文档 docs/dogfooding-pull-requests.md 展开并结合 get-aspire-cli-pr.sh 与 get-aspire-cli-pr.ps1 两个辅助脚本的源码实现完整讲解如何本地试用dogfood某个 PR 中构建出的 Aspire CLI 及其配套 NuGet 包从四种安装模式archive / tool / winget / homebrew的适用场景、PR 级 NuGet hive 隔离机制、channel 命名体系到aspire init脚手架如何自动把生成的 C# AppHost 项目锁定到 PR 构建的包源以及常见故障排查与清理方法。读完后你可以独立完成拿到一个 PR 号 → 装上该 PR 的 CLI 和包 → 用它们创建、构建、运行新项目 → 干净卸载的完整闭环。核心机制PR 构建产物与四种安装模式Aspire 的每次 PR CI 运行ci.ymlworkflow都会产出一组构建工件artifacts面向特定运行时标识符RID的原生 CLI 归档、跨平台 NuGet 包、以及为 WinGet / Homebrew 预生成的清单文件。Dogfooding 的本质就是把这些工件从 GitHub Actions 拉下来装进一个与正式版隔离的本地目录中。仓库提供两个跨平台的辅助脚本功能等价、参数一一对应Basheng/scripts/get-aspire-cli-pr.shPowerShelleng/scripts/get-aspire-cli-pr.ps1脚本会自动检测当前操作系统与 CPU 架构定位该 PR 最新一次成功的ci.ymlworkflow 运行然后下载对应工件。从 Bash 脚本头部的常量定义可以确认各模式实际消费的工件名称get-aspire-cli-pr.sh#L12-L18用途工件名跨平台 NuGet 包built-nugetsRID 专属 NuGet 包built-nugets-for-rid原生 CLI 归档cli-native-archives-ridWinGet 预发布清单winget-manifests-prereleaseHomebrew 预发布 caskhomebrew-cask-prerelease脚本支持四种 CLI 安装模式区别仅在于CLI 二进制本身如何获取所有模式都会把该 PR 的 NuGet 包灌入同一个 PR 级 hive位于~/.aspire/hives/pr-PR_NUMBER/packages从而使aspire new、aspire add、aspire run都能解析到同一份 PR 构建的包Archive 模式默认从cli-native-archives-rid工件安装原生 CLI 归档到 PR 专属目录并填充 PR hive。适合希望aspire new、aspire add、aspire update等项目/包操作全部使用同一 PR 构建包的场景。Tool 模式从 PR 的built-nugets-for-rid工件以 .NET 工具形式安装Aspire.Cli同时从跨平台built-nugets工件填充 PR hive。适合你想连Aspire.Clidotnet-tool 打包/获取路线一起试用时。WinGet 模式下载 PR 生成的winget-manifests-prerelease工件与两个 Windows 原生归档工件改写清单指向本地归档文件后经 WinGet 安装。仅支持 Windows。Homebrew 模式下载 PR 生成的homebrew-cask-prerelease工件与两个 macOS 原生归档工件改写 cask 指向本地归档后经 Homebrew 安装。仅支持 macOS。从 Bash 脚本的get_installer_archive_rids函数get-aspire-cli-pr.sh#L1088-L1101可以看到WinGet 模式固定拉取win-x64与win-arm64两个 RID 的归档Homebrew 模式固定拉取osx-arm64与osx-x64这解释了为什么这两个模式要求下载两个原生归档工件。前置条件执行脚本前请确认本机满足以下条件与文档 docs/dogfooding-pull-requests.md 的 Prerequisites 一节一致已安装并认证 GitHub CLI安装地址见 cli.github.com认证命令为gh auth login使用--local-dir从本地目录安装时可不依赖gh。可访问 GitHub Actions 的网络环境。Tool 模式--install-mode tool/-InstallMode Tool要求 PATH 上有 .NET SDK 的dotnet命令因为脚本会 shell 出dotnet tool install。WinGet 模式要求 Windows 上可用 WinGetBash 脚本实际通过pwsh调用 dogfood 脚本因此也需要 PowerShell见 get-aspire-cli-pr.sh#L1252-L1266 的环境校验。Homebrew 模式要求 macOS 上可用 Homebrew。归档解压工具Unix/macOS 需要tar和/或unzip脚本按扩展名选择.zip用unzip.tar.gz用tar见 get-aspire-cli-pr.sh#L469-L489Windows 上 PowerShell 脚本使用内置解压Git Bash 下跑.sh脚本则需自备unzip/tar。一行式one-liner用法额外需要 Bash 的curl或 PowerShell 内置的irm/Invoke-RestMethod。两条实用备注Alpine 等 musl 发行版请使用--os linux-muslBash或-OS linux-muslPowerShell。目标默认是microsoft/aspire可通过环境变量ASPIRE_REPOowner/repo指向你的 fork脚本中对应readonly REPO${ASPIRE_REPO:-microsoft/aspire}见 get-aspire-cli-pr.sh#L20-L22。四种安装模式详解Archive 模式默认./eng/scripts/get-aspire-cli-pr.sh 1234./eng/scripts/get-aspire-cli-pr.ps1 1234脚本从 PR 的cli-native-archives-rid工件中下载归档、解压到 PR 专属的bin目录并把built-nugets工件里的全部*.nupkg复制到 PR hive。归档内必须恰好包含一个aspire-cli-*.tar.gz或aspire-cli-*.zip文件脚本会递归搜索并在零个或多个匹配时明确报错download_aspire_cli函数get-aspire-cli-pr.sh#L1036-L1062。Tool 模式./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode tool./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode ToolTool 模式默认以全局 .NET 工具形式安装dotnet tool install --global按 .NET SDK 的全局工具约定把入口放到 PATH 上。若Aspire.Cli已作为 .NET 工具安装重新运行时加--forceBash或-ForcePowerShell即可更新到 PR 版本——包括降级。这一点在源码中得到印证install_or_update_aspire_cli_tool函数在FORCE为真时改用dotnet tool update ... --allow-downgrade否则执行dotnet tool install且两种情况都通过--add-source $hive_dir把包源指到已填充的 PR hiveget-aspire-cli-pr.sh#L841-L885。脚本会先在 hive 里精确定位唯一的Aspire.Cli.version.nupkg排除 RID 专属包与符号包再以该精确版本号安装find_aspire_cli_package_versionget-aspire-cli-pr.sh#L779-L835。若不想改动全局 .NET 工具安装可以传自定义安装路径脚本会把它转成dotnet tool --tool-path实际落在前缀下的 PR 专属bin目录./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode tool --install-path ~/.aspire-pr./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode Tool -InstallPath $HOME/.aspire-pr注意 tool 模式不支持跨 RIDvalidate_tool_mode_runtime_identifier会校验目标 OS/arch 与宿主机一致否则报错提示改用 archive 模式做跨 RID 下载get-aspire-cli-pr.sh#L887-L910。WinGet 模式./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode winget./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode WinGet流程为下载 PR 生成的 WinGet 清单工件 → 下载win-x64与win-arm64两个原生归档 → 改写清单使其指向本地归档文件 → 通过 WinGet 安装。WinGet 模式仅支持 Windows若已通过 WinGet 安装过Microsoft.Aspire需先卸载或传--force/-Force允许 dogfood 清单覆盖它。源码中该模式最终执行的是工件内与*.installer.yaml同目录的dogfood.ps1 -ArchiveRoot dirget-aspire-cli-pr.sh#L1198-L1230。Homebrew 模式./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode homebrew./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode Homebrew流程对称下载homebrew-cask-prerelease工件与osx-arm64/osx-x64两个归档改写 cask 指向本地归档执行工件内与aspire.rb同目录的dogfood.sh --archive-root dir完成安装。Homebrew 模式仅支持 macOS若已安装aspirecask先执行brew uninstall --cask aspire。cask 本身的设计可以在 eng/homebrew/aspire.rb.template 中看到二进制完整安装在 Caskroom 版本目录内postflight 阶段写入.aspire-install.jsonsidecar 标记安装渠道且刻意保留空的zap trash: []——原因见后文卸载/清理一节。安装落点与 hive 机制各模式下的安装位置与隔离边界如下What gets installed 一节Aspire CLI 二进制Archive 模式默认位于~/.aspire/dogfood/pr-PR_NUMBER/bin/aspireWindows 为aspire.exe。源码中compute_cli_install_dir明确了这一约定有 PR 号时为prefix/dogfood/pr-N/bin否则回落到共享的prefix/binget-aspire-cli-pr.sh#L1437-L1446。Tool 模式默认走dotnet tool install --global的全局工具约定与--install-path组合时脚本把前缀下的 PR 专属bin目录作为--tool-path。WinGet/Homebrew 模式由平台包管理器托管安装位置。隔离语义同一前缀下同 PR 的安装会被重复运行覆盖其他 PR 的安装以及常规脚本安装~/.aspire/bin互不影响。PR 级 NuGet hive默认位于~/.aspire/hives/pr-PR_NUMBER/packages所有安装模式都会填充。这是一个本地、PR 专属的包仓库与你的全局 NuGet 缓存及其他项目完全隔离——你可以只用该 PR 构建产出的包创建新项目。Bash 脚本的install_built_nugets会先清空目标目录再复制工件中所有*.nupkg保证 hive 内容与该次构建完全一致get-aspire-cli-pr.sh#L978-L1006。一个文档未明说、但源码给出的细节archive 模式安装完成后脚本会在二进制旁写入.aspire-install.jsonsidecar内容为{source:pr}write_pr_route_sidecarget-aspire-cli-pr.sh#L1448-L1472。该标记让aspire update等下游逻辑识别出这是 PR 渠道安装不会按 stable 脚本源去假设更新路径——这与 Homebrew cask 写入{source:brew}sidecar 的设计是同一套安装路由标记机制。关于 PATHarchive 模式下脚本会尝试把 PR 专属bin目录加入 shell profile自动识别 bash/zsh/fish/sh 并写入对应的export PATH/fish_add_path语句见 get-aspire-cli-pr.sh#L532-L621新终端即可直接调用aspire若未自动生效按脚本提示信息手动添加即可。默认 tool 模式的 PATH 交给dotnet tool install --globaltool 模式 自定义路径时脚本同样可以把 PRbin目录加入 PATHWinGet/Homebrew 模式的 PATH 交给平台包管理器。此外Bash 脚本还支持下载并安装该 PR 构建的 VS Code 扩展aspire-extension工件中的.vsix通过code --install-extension安装可用--skip-extension跳过、--use-insiders改装到 VS Code Insiders--local-dir还支持直接从本地目录甚至dotnet build的原始输出目录安装hive label 可从包名中的pr.N.gsha版本后缀自动推断。Channel 名称CLI 与包源的绑定关系每个 Aspire CLI 二进制都针对一个特定 channel 构建。channel 名决定aspire new、aspire add等命令使用哪个包源或本地 hive也是aspire update --self --channel的取值。完整对照表Channel说明stable正式发布构建。多数用户的默认值。stagingRC 与预览构建。daily最新每日 CI 构建。local本地源码构建。使用~/.aspire/hives/local/packages/作为包源。这是未显式传/p:AspireCliChannel的开发者构建的默认 channel。pr-N单个 PR 的 CI 构建例如pr-16820。使用~/.aspire/hives/pr-N/packages/作为包源。PR dogfooding 会安装pr-N的 CLI 并自动填充对应 hive 目录——archive 与 tool 两种安装模式均如此无需手动设置 channel。CLI 侧的实现在 src/Aspire.Cli/CliExecutionContext.cs 中可见执行上下文持有HivesDirectory与IdentityChannel并把local、pr-*等 hive 子目录作为可发现的包渠道计数。快速上手警告在运行以下命令前请务必先仔细审查该 PR 的代码确认其安全。任选一种方式把1234换成你要试用的 PR 号一行式Bash远程执行 main 分支上的脚本archive 模式curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 1234远程执行并以 dotnet tool 模式安装curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 1234 --install-mode tool一行式PowerShelliex { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 1234iex { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 1234 -InstallMode Tool从本地克隆执行Bash / PowerShell./eng/scripts/get-aspire-cli-pr.sh 1234./eng/scripts/get-aspire-cli-pr.ps1 1234脚本如何定位 PR 的 CI 运行值得了解底层流程便于排障脚本先通过 GraphQL 查询取 PR 的 head SHA失败时回退到 REST APIget_pr_head_shaget-aspire-cli-pr.sh#L668-L710再调用 GitHub Actions API 查询该 SHA 上eventpull_request的ci.yml运行取最新一条的 run idfind_workflow_runget-aspire-cli-pr.sh#L912-L931之后的所有下载都是gh run download run-id -R repo --name artifact。这也解释了PR 刚推了新提交时要等 CI 跑完这一排障建议的由来。常用选项速查脚本自动检测 OS/arch 并定位 PR 最新ci.yml运行以下选项用于覆盖默认行为指定 workflow 运行存在多次运行或需要固定某次时Bash./eng/scripts/get-aspire-cli-pr.sh 1234 --run-id 987654321PowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -WorkflowRunId 987654321提示run ID 可见于 Actions 运行页面 URL。选择安装位置默认~/.aspireBash./eng/scripts/get-aspire-cli-pr.sh 1234 --install-path ~/.aspire-prPowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallPath $HOME/.aspire-pr覆盖 OS 与架构默认自动检测允许的 OS 值win、linux、linux-musl、osx允许的架构值x64、arm64。Tool 模式下dotnet tool install只按当前宿主机解析 RID 专属包OS/arch 覆盖应配合 archive 模式用于跨 RID 下载而不是给另一个 RID 交叉安装 dotnet tool。Bash./eng/scripts/get-aspire-cli-pr.sh 1234 --os linux --arch arm64PowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -OS linux -Architecture arm64只取 NuGet hive不装 CLIBash--hive-onlyPowerShell-HiveOnly仅 archive 模式有效。以 dotnet tool 形式安装Bash--install-mode tool或简写-m toolPowerShell-InstallMode Tool已有工具安装挡住目标版本时用--force/-Force。经平台包管理器安装WinGet 用--install-mode winget/-InstallMode WinGetHomebrew 用--install-mode homebrew/-InstallMode Homebrew。详细输出 / 保留归档 / 干跑Bash-v/--verbose、-k/--keep-archive、--dry-runPowerShell-Verbose、-WhatIfPowerShell 式 dry-run。--dry-run只会打印将要做什么而不触碰文件系统源码中对下载、安装、PATH 修改均有[DRY RUN]分支。指向 forkBashASPIRE_REPOmyfork/aspire ./eng/scripts/get-aspire-cli-pr.sh 1234PowerShell$env:ASPIRE_REPO myfork/aspire; ./eng/scripts/get-aspire-cli-pr.ps1 1234典型用法示例安装 PR 1234 的 CLI 包默认位置Bash./eng/scripts/get-aspire-cli-pr.sh 1234PowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234全局安装该 PR 的Aspire.Clidotnet toolBash./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode toolPowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode Tool把已有的全局Aspire.Cli工具更新或降级到 PR 版本Bash./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode tool --forcePowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode Tool -Force把 PR 的 dotnet tool 装到隔离路径Bash./eng/scripts/get-aspire-cli-pr.sh 1234 --install-mode tool --install-path ~/.aspire-prPowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -InstallMode Tool -InstallPath $HOME/.aspire-prAlpinemuslarm64 装入自定义前缀Bash./eng/scripts/get-aspire-cli-pr.sh 1234 --os linux-musl --arch arm64 --install-path ~/.aspire-alpine只取 NuGet 包不装 CLI并输出详细信息Bash./eng/scripts/get-aspire-cli-pr.sh 1234 --hive-only --verbosePowerShell./eng/scripts/get-aspire-cli-pr.ps1 1234 -HiveOnly -VerboseC# AppHost 脚手架PR 包如何进入生成的项目当使用pr-N渠道的 CLI例如上面脚本安装出来的对某工作区执行aspire init时命令会向解决方案根目录写入一份工作区级NuGet.config把包源固定到对应的~/.aspire/hives/pr-N/packages/。此后脚手架生成的 C# AppHost 在还原包时会从该 hive 解析 PR 构建出的Aspire.Hosting.*包与Aspire.AppHost.Sdk。这一行为在 CLI 源码中有直接对应src/Aspire.Cli/Commands/InitCommand.cs 中的注释明确要求确保工作区拥有暴露运行中 CLI 二进制身份渠道identity-channel包源的 NuGet.config且该步骤刻意放在apphost.cs已存在检查之前执行以便恢复旧版损坏的 CLI 没留下工作区 NuGet.config的场景InitCommand.cs#L391-L400 进一步说明由CliExecutionContext.IdentityChannelstable / staging / daily /pr-N/ local驱动渠道选择用pr-NCLI 脚手架的开发者的项目会自动接到匹配的pr-Nhive。同样的机制适用于其他非 stable 渠道staging、daily会指向对应的远程 Azure DevOps 包源local与run-*则指向本地 hive。该NuGet.config的作用域仅限解决方案目录只影响其下项目不会改动你的用户级或机器级 NuGet 配置。故障排查No workflow run found确认该 PR 已有一次跑完的ci.yml运行PR 刚更新时等待 CI 完成。已知目标运行时直接传--run-id/-WorkflowRunId。Failed to download artifact … may not be available yet运行可能仍在进行或工件尚未发布CI 完成后重试。脚本的报错信息中会附该次运行的 Actions 页面地址供核对工件。GitHub CLI not installed/authenticated安装gh并执行gh auth login。归档解压报错Bash 脚本路径下确认tar和/或unzip可用。The .NET SDK dotnet command is requiredtool 模式需要dotnet在 PATH 上源码中check_dotnet_dependency会先校验见 get-aspire-cli-pr.sh#L768-L777。Aspire.Cliis already installed 或 PR 版本低于已装版本导致安装失败重跑并加 Bash--force/ PowerShell-Force脚本会改用dotnet tool update --allow-downgrade。卸载与清理Archive 模式的 PR CLI删除~/.aspire/dogfood/pr-PR_NUMBER/bin/aspireWindows 为aspire.exe如脚本加过 PATH 条目从 shell profile 中移除。全局 tool 模式安装dotnet tool uninstall --global Aspire.Cli。自定义路径的 tool 模式安装删除自定义前缀下的 PR 专属bin目录例如~/.aspire-pr/dogfood/pr-PR_NUMBER/bin如加过 PATH 条目则一并移除。PR 专属包删除~/.aspire/hives/pr-PR_NUMBER/packages。Homebrew 卸载注意事项Homebrew cask模板见 eng/homebrew/aspire.rb.template把 Aspire 完整安装在 Caskroom 版本目录内——brew uninstall aspire会端到端移除二进制与 route sidecar。cask 刻意携带空的zap语句zap trash: []原因是~/.aspire/是脚本安装路线与 PR 安装路线共享的前缀若由 brew 递归删除会破坏这些安装路线仍持有的状态模板中的注释对此有完整说明aspire.rb.template#L37-L45。如果在本模板合入前就通过 Homebrew cask 装过~/.aspire/installs/brew-stable/下可能残留旧的 dogfood 状态目录新 cask 不会触碰该路径brew uninstall也不会删除它。升级 cask 后手动清理一次rm -rf ~/.aspire/installs/brew-stable~/.aspire/hives/下的 NuGet hive以及~/.aspire/bin/、~/.aspire/dogfood/下的脚本路线/PR 路线二进制双向都不属于 cask 的管理范围请按上文各路线的清理步骤处理。安全须知一行式命令执行的是从仓库拉取下来的脚本。如有疑虑先审查脚本源码再运行Basheng/scripts/get-aspire-cli-pr.shPowerShelleng/scripts/get-aspire-cli-pr.ps1同理dogfood 的 PR 构建本身未经正式发布流程校验建议先审查 PR 代码再运行与快速上手的警告一致。配合--dry-run可以在不触碰文件系统的前提下预览完整的下载与安装动作是执行前快速核对行为的良好习惯。【免费下载链接】aspireAspire is the tool for code-first, extensible, observable dev and deploy.项目地址: https://gitcode.com/GitHub_Trending/as/aspire创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表