.NET Core dotnet恢复失败与System.ArgumentNullException在詹金斯上 [英] .NET Core dotnet restore failing on jenkins with System.ArgumentNullException

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

问题描述

我正在尝试使用.NET Core CLI命令 点网还原 在詹金斯上.当我以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:\ test"传递给dotnet restore时,这种方法失败了.

1) This fails the same way when I pass in the parameter "--packages C:\test" 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:\ Users \ Default目录,而不是正确的用户目录.因此,它不会选择环境变量%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:\Users\Default 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 Files \ dotnet \ sdk \ 1.0.4 \ NuGet.targets(97,5):错误:值不能为null. [D:\ Workspaces \ WEBCORE \ WebStarter.sln] C:\ Program Files \ dotnet \ sdk \ 1.0.4 \ NuGet.targets(97,5):错误:参数名称:path1 [D:\ Workspaces \ WEBCORE \ WebStarter.sln]

C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Value cannot be null. [D:\Workspaces\WEBCORE\WebStarter.sln] C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Parameter name: path1 [D:\Workspaces\WEBCORE\WebStarter.sln]

看起来像一个类似的问题.需要设置哪些环境变量才能使dotnet恢复运行?

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%\AppData\Roaming
    set LOCALAPPDATA=%USERPROFILE%\AppData\Local

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

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