【发布时间】:2017-12-18 11:48:29
【问题描述】:
我正在尝试使用 .NET Core CLI 命令 点网还原 关于詹金斯。当我以 Jenkins 使用的用户身份登录时,使用解决方案导航到工作区文件夹,它就可以工作。但是,当我创建 Jenkins 作业并添加构建步骤来执行命令时,我得到了
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: path1
at System.IO.Path.Combine(String path1, String path2, String path3)
at NuGet.Common.NuGetEnvironment.GetFolderPath(NuGetFolderPath folder)
at NuGet.Configuration.SettingsUtility.GetHttpCacheFolder()
at NuGet.Configuration.NuGetPathContext.Create(ISettings settings)
at Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
at Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
有什么奇怪的:
1) 当我将参数“--packages C:\test”传递给 dotnet restore 时,这同样会失败。
2) 调用堆栈表明它认为它正在第一次运行和配置 .NET Core。尽管之前已经以该用户身份运行过它。
3) 我读到默认情况下 dotnet restore 会将包还原到您的 %USERPROFILE% 目录。奇怪的是,当我将 jenkins 任务发送到 ECHO %USERPROFILE% 时,它返回 C:\Users\Default 目录,而不是正确的用户目录。所以它没有选择环境变量 %USERPROFILE%。
为什么 Jenkins 每次都认为它是第一次配置 .NET Core,为什么它没有正确的用户目录,有没有办法解决这些问题来运行 .NET Core CLI?
更新:我深入研究了 nuget 代码,发现它正在尝试查找 LOCALAPPDATA。我在 Jenkins 中设置了这个,但现在我得到了错误
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5):错误:值不能为空。 [D:\Workspaces\WEBCORE\WebStarter.sln] C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): 错误:参数名称:path1 [D:\Workspaces\WEBCORE\WebStarter.sln]
看起来类似的问题。运行 dotnet restore 需要设置哪些环境变量?
【问题讨论】:
-
最后我通过使用 SET 提取所有 Windows 环境变量来解决这个问题。然后我创建了一个批处理脚本来设置它们,并在调用 dotnet restore 之前从 Jenkins 作业中调用它。