Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Dotnet tool restore' does not work correctly when NUGET_PACKAGES (global-packages) is set to an alternative location #11432

Open
da9l opened this issue Apr 24, 2020 · 21 comments · May be fixed by #43576

Comments

@da9l
Copy link

da9l commented Apr 24, 2020

Issue Title

'dotnet tool restore' does not work correctly when NUGET_PACKAGES (global-packages) is set to an alternative location.

Description

If you set NUGET_PACKAGES to an alternate folder. "D:\cache" on a build agent for instance,

dotnet tool restore # and then directly after
dotnet paket info # or paket <whatever>.

will fail with $lastexitcode=1 and
Run "dotnet tool restore" to make the "paket" command available.

The same error happens for at least two other tools as well. gitversion.tool and dotnet-fsharplint.

Repro steps

See this minimal example: https://github.com/da9l/dotnetpaketProblem_minimalExample/blob/master/readme.md

Expected behavior

it should work.

Actual behavior

fail with $lastexitcode=1 and
Run "dotnet tool restore" to make the "paket" command available.

Known workarounds

Don't set NUGET_PACKAGES to anything non-standard.

@mairaw mairaw transferred this issue from dotnet/core Apr 25, 2020
@pagebrooks
Copy link

pagebrooks commented Sep 11, 2020

We ran into this issue as well. As a workaround, we had to create a symbolic link from the standard location to our customized location so that the dotnet cli would behave properly.

> mklink /J "C:\Users\username\.nuget\packages" "X:\CustomPath\.nuget\packages"

@Jacknq
Copy link

Jacknq commented Nov 25, 2020

hi,
same issue here, its connected to v 1.0.1 , if i install 0.50 it works, if i upgrade it fails always with

Run "dotnet tool restore" to make the "dotnet-script" command available.

win 10 x64
sdks installed
2.1.811 [C:\Program Files\dotnet\sdk]
3.1.301 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]

nuget

 <config>
    <add key="repositoryPath" value="./../pckgs" />
  </config>
PS D:\work\dev\vuecore> dotnet tool uninstall dotnet-script
Tool 'dotnet-script' was successfully uninstalled and removed from manifest file D:\work\dev\vuecore\.config\dotnet-tools.json.
You can invoke the tool from this directory using the following commands: 'dotnet tool run dotnet-script' 
work\dev\vuecore\.config\dotnet-tools.json.
PS D:\work\dev\vuecore> dotnet script test.csx
Run "dotnet tool restore" to make the "dotnet-script" command available.
PS D:\work\dev\vuecore> dotnet tool restore
Tool 'dotnet-script' (version '1.0.1') was restored. Available commands: dotnet-script

Restore was successful.
PS D:\work\dev\vuecore> dotnet script test.csx
Run "dotnet tool restore" to make the "dotnet-script" command available.

how to reproduce
install the tool globally, uninstall, install and uninstall locally, repeat locally, doesnt work

@detoxhby
Copy link

Still happens with latest SDK. It makes local tooling unusable for teams as restore cannot be used and developers are forced to reinstall the tools by hand which is something that could be avoided by local tooling manifest usage.

Any reliable workaround for using custom packages path with local tools?

@jespergustinmsft
Copy link

jespergustinmsft commented Oct 4, 2021

I just want to share my findings; that I managed to work around it by deleting the %USERPROFILE%\.dotnet\toolResolverCache folder before running dotnet tool restore.

@szakib
Copy link

szakib commented Jan 14, 2022

We have the same issue.

@slav
Copy link

slav commented Jan 24, 2022

deleting toolResolverCache seems to fix the issue. On linux it's at ~/.dotnet/toolResolverCache

@szakib
Copy link

szakib commented Jan 25, 2022

The most robust workaround I have found. Assuming Windows, NuGet packages at c:\NuGet, powershell:
if (-Not (Get-Item -Path '$Env:USERPROFILE\.dotnet\toolResolverCache' -Force).LinkType) { Remove-Item -Force -Recurse '$Env:USERPROFILE\.dotnet\toolResolverCache'; New-Item -ItemType Junction -Path '$Env:USERPROFILE\.dotnet\toolResolverCache' -Target 'C:\NuGet' }
You can run this blindly on all build agents or stick it in a group policy object / login script.

@bondarenkod
Copy link

I just want to share my findings; that I managed to work around it by deleting the %USERPROFILE%.dotnet\toolResolverCache folder before running dotnet tool restore.

You saved my day, thank you!

@iamjplant
Copy link

This workaround does seem to be sufficient for now. Are there plans to fix this issue, however?

@baronfel baronfel added Area-Tools untriaged Request triage from a team member labels Jul 8, 2022
@gkulin gkulin assigned gkulin and unassigned gkulin Aug 3, 2022
@gkulin gkulin added needs team triage Requires a full team discussion and removed untriaged Request triage from a team member labels Aug 3, 2022
@marcpopMSFT marcpopMSFT added this to the 8.0.1xx milestone Aug 3, 2022
@marcpopMSFT marcpopMSFT removed the needs team triage Requires a full team discussion label Aug 3, 2022
@zerovian
Copy link

zerovian commented Oct 3, 2022

Same problem for us. We run tests in parallel and those tests do project restores which often have the same set of files that need to be downloaded from a nuget feed. We put in the override in the nuget.config to make each test use a separate packages cache to avoid the concurrency problem. Because of this issue: NuGet/Home#8129

But now that we're trying to incorporate use of tools, the restore fails on some machines. Deleting the 'toolResolverCache' folder for the user helps, but that's terrible in a concurrent test environment where multiple tests need the tool. And we also do not want to install stuff globally.

@zerovian
Copy link

zerovian commented Oct 3, 2022

Seems like we need a way in the nuget.config file (and/or environment varaible) to specify the toolResolverCache location so we can point to a local folder in the same way we can point to a local packages cache.

@iamjplant
Copy link

Same problem for us. We run tests in parallel and those tests do project restores which often have the same set of files that need to be downloaded from a nuget feed. We put in the override in the nuget.config to make each test use a separate packages cache to avoid the concurrency problem. Because of this issue: NuGet/Home#8129

But now that we're trying to incorporate use of tools, the restore fails on some machines. Deleting the 'toolResolverCache' folder for the user helps, but that's terrible in a concurrent test environment where multiple tests need the tool. And we also do not want to install stuff globally.

Like you say, it's pretty rough in a concurrent test environment. It's causing some headaches.

@alexrp
Copy link

alexrp commented Apr 11, 2023

Redirecting globalPackagesFolder is actually quite important for some scenarios, e.g. testing custom MSBuild SDKs. It's not really reasonable to tell people they might have to nuke a cache in their home directory to work on my project.

@reynoldsa
Copy link

This might have renewed relevance given the release in Windows' Dev channel preview of Dev Drive, where an explicitly called-out use case is to redirect package caches there. I recently hit this myself and got around it with the workaround, but when this hits GA more developers may encounter this.

@MiYanni MiYanni self-assigned this Jul 27, 2023
@MiYanni MiYanni removed their assignment Aug 22, 2023
@marcpopMSFT marcpopMSFT removed this from the 8.0.1xx milestone Sep 19, 2023
@marcpopMSFT marcpopMSFT added this to the 8.0.2xx milestone Sep 19, 2023
@molesmoke
Copy link

Likewise, I just switched to dev drive and found that dotnet tool restore doesn't work with it...

@baronfel
Copy link
Member

This is on our list to tackle - it's one of the things that we have more control over now that we're not doing an behind-the-scenes dotnet restore on a specially-formatted project file. We're in more direct control of the tool package download so can respond to changes like this more directly.

@Jacknq
Copy link

Jacknq commented Nov 29, 2023

This is on our list to tackle - it's one of the things that we have more control over now that we're not doing an behind-the-scenes dotnet restore on a specially-formatted project file. We're in more direct control of the tool package download so can respond to changes like this more directly.

Quite a challenge to tackle it since its 3 years already...

@klemmchr
Copy link

klemmchr commented Jun 2, 2024

Stumbled upon this after setting up my DevDrive. What is the status on this? Looks like no progress for the past 6 months.

@jeremy-visionaid
Copy link

@klemmchr I think everyone's just using the symlink workaround still

@diegosasw
Copy link

@klemmchr I think everyone's just using the symlink workaround still

This is a better workaround in my opiniopn #11432 (comment)

@klemmchr
Copy link

@klemmchr I think everyone's just using the symlink workaround still

This is a better workaround in my opiniopn #11432 (comment)

That is only a temporary workaround and will not completely resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.