Jenkins slave not able to find dotnet When I check for dotnet version it is throwing an error 

D:\jenkins\workspace\csharp-windows-test&gt;dotnet --version 
17:58:06 System.ArgumentNullException: Value cannot be null.
17:58:06 Parameter name: path1
17:58:06    at System.IO.Path.Combine(String path1, String path2)
17:58:06    at Microsoft.DotNet.Configurer.CliFolderPathCalculator.get_DotnetUserProfileFolderPath()
17:58:06    at Microsoft.DotNet.Configurer.FirstTimeUseNoticeSentinel..ctor(CliFolderPathCalculator cliFolderPathCalculator)
17:58:06    at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
17:58:06    at Microsoft.DotNet.Cli.Program.Main(String[] args)
17:58:06 


but when I search for 'where' it shows the location

17:58:06 D:\jenkins\workspace\csharp-windows-test&gt;where dotnet  
17:58:07 C:\Program Files\dotnet\dotnet.exe


This is causing build failures. Can someone suggest a best way to resolve this 

Also I was able to execute the script on the machine directly without issues. This is only happening when called from Jenkins
When I did echo %USERPROFILE% from Jenkins it returned null. So I had to 
manually set USERPROFILE value from Jenkins as environment variable. Also I had to set these

APPDATA=%USERPROFILE%\AppData\Roaming

LOCALAPPDATA=%USERPROFILE%\AppData\Local