我们使用 Cakebuild.net 提供的标准 build.ps1 PowerShell 脚本
它在 CI 和开发人员机器上都表现出色,但是对于我们的 1 位开发人员,我们在启动 build.ps1 时收到以下错误
Unable to find package 'Cake'
然后退出,检查 tools 文件夹中没有安装 Cake。
您收到的错误是因为 NuGet 控制台在机器上配置的提要中找不到 Cake 包。
您可以通过更改build.ps中的以下行来测试这个理论
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
至
$NuGetOutput = Invoke-Expression "&`"$NUGET_EXE`" install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`" -Source `"https://www.nuget.org/api/v2`""
如果这可行,您的同事的机器可能缺少或在他的机器上禁用了标准的 nuget.org 提要。
您可以使用这样的 NuGet 控制台列出您已配置的源(如果路径中没有 nuget 控制台,它应该在 repo 工具文件夹中可用)
nuget sources list
然后它应该列出 nuget.org 的 v2 和/或 v3 提要,并且它们后面应该有如下[Enabled]
文本
Registered Sources:
1. https://www.nuget.org/api/v2/ [Enabled]
https://www.nuget.org/api/v2/
2. https://api.nuget.org/v3/index.json [Enabled]
https://api.nuget.org/v3/index.json
如果它们已列出但已禁用,您可以通过键入启用它们
nuget source enable -Name https://www.nuget.org/api/v2/
或者
nuget source enable -Name https://api.nuget.org/v3/index.json
根据您注册和禁用的提要,如果缺少源,则可以通过键入来添加它们
nuget sources add -Name https://www.nuget.org/api/v2/ -Source https://www.nuget.org/api/v2/
设置存储在其中,%AppData%\NuGet\NuGet.config
因此您可以手动编辑该文件,以确保团队中的每个人都使用相同的源,您可以将 a 添加NuGet.config
到存储库的根目录,因为 nuget 尝试在路径中查找配置,然后回退到应用程序数据。