.NET Core dotnet 还原在 jenkins 上失败并带有 System.ArgumentNullException [英] .NET Core dotnet restore failing on jenkins with System.ArgumentNullException

查看:22
本文介绍了.NET Core dotnet 还原在 jenkins 上失败并带有 System.ArgumentNullException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 .NET Core CLI 命令dotnet 还原在詹金斯.当我以 Jenkins 使用的用户身份登录时,导航到包含解决方案的工作区文件夹,它工作正常.但是,当我创建一个 Jenkins 作业并添加一个构建步骤来执行命令时,我得到

I'm trying to use the .NET Core CLI command dotnet restore on jenkins. When I log in as the user Jenkins uses, navigate to the workspace folder with the solution, it works. However when I create a Jenkins job and add a build step to execute a command, I get

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: est"传递给 dotnet restore 时,这会以同样的方式失败.

1) This fails the same way when I pass in the parameter "--packages C: est" to dotnet restore.

2) 调用堆栈表明它认为它是第一次运行和配置 .NET Core.尽管之前已经以该用户身份运行过.

2) The callstack indicates it thinks it is running and configuring .NET Core for the first time. This is despite having already run it as this user before.

3) 我读到默认情况下 dotnet restore 会将包还原到您的 %USERPROFILE% 目录.奇怪的是,当我将 jenkins 任务交给 ECHO %USERPROFILE% 时,它返回 C:UsersDefault 目录,而不是正确的用户目录.所以它没有选择环境变量 %USERPROFILE%.

3) I've read that by default dotnet restore restores packages to your %USERPROFILE% directory. Oddly, when I just get the jenkins task to ECHO %USERPROFILE%, it returns the C:UsersDefault directory, rather than the correct user directory. So it is not picking up the environment variable %USERPROFILE%.

为什么 Jenkins 每次都认为是第一次配置 .NET Core,为什么没有正确的用户目录,有没有办法解决这些问题来运行 .NET Core CLI?

Why does Jenkins think it is configuring .NET Core for the first time every time, why does it not have the correct user directory, and is there a way to work around these issues to run the .NET Core CLI?

更新:我深入研究了 nuget 代码,发现它正在尝试查找 LOCALAPPDATA.我在 Jenkins 中设置了这个,但现在出现错误

Update: I delved into the nuget code and found it was trying to find LOCALAPPDATA. I set this in Jenkins but now I get the error

C:Program Filesdotnetsdk1.0.4NuGet.targets(97,5):错误:值不能为空.[D:WorkspacesWEBCOREWebStarter.sln]C:Program Filesdotnetsdk1.0.4NuGet.targets(97,5): 错误:参数名称:path1 [D:WorkspacesWEBCOREWebStarter.sln]

C:Program Filesdotnetsdk1.0.4NuGet.targets(97,5): error : Value cannot be null. [D:WorkspacesWEBCOREWebStarter.sln] C:Program Filesdotnetsdk1.0.4NuGet.targets(97,5): error : Parameter name: path1 [D:WorkspacesWEBCOREWebStarter.sln]

看起来是类似的问题.运行dotnet restore需要设置哪些环境变量?

Looks like a similar issue. What environment variables need to be set for dotnet restore to run?

推荐答案

同样的问题发生在 Bamboo Windows 代理上.解决方案涉及设置以下环境变量.在 dotnet core SDK v2.1.302 上测试.

The same issue occurs on Bamboo Windows agents. The solution involved setting the following environment variables. Tested on dotnet core SDK v2.1.302.

    set HOMEPATH=%USERPROFILE%
    set APPDATA=%USERPROFILE%AppDataRoaming
    set LOCALAPPDATA=%USERPROFILE%AppDataLocal

这篇关于.NET Core dotnet 还原在 jenkins 上失败并带有 System.ArgumentNullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆