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

Need consistent way of getting NuGet package cache location from MSBuild #6301

Closed
clairernovotny opened this issue Dec 12, 2017 · 9 comments
Closed
Labels
Functionality:Restore Resolution:Question This issues appears to be a question, not a product defect
Milestone

Comments

@clairernovotny
Copy link

Currently NUGET_PACKAGES can be used to alter the package cache location. The issue is that anything in custom msbuild targets that need to call into packages have to check multiple possible locations since there is no consistent property defined for this purpose.

The default is %USERPROFILE%\.nuget\packages, and as NUGET_PACKAGES isn't widely used, to workaround other issues, or simply to access tools within a package, many build scripts "hardcode" a path like this:
https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/blob/22e4d8b20bf5efb40ea10620aef6c55f69dbbf3c/Directory.Build.props#L33-L36
or https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/blob/22e4d8b20bf5efb40ea10620aef6c55f69dbbf3c/.vsts.nightly.ci.yml#L22

In those cases, if NUGET_PACKAGES is set, it'll cause builds to be incorrect or break.

I propose that a new property be added to the build-in/default NuGet props that calculates this correctly and is defined for this purpose. Default to %USERPROFILE%\.nuget\packages but return %NUGET_PACKAGES% if set.

/cc @chrispatterson @AArnott

@AArnott
Copy link
Contributor

AArnott commented Dec 12, 2017

What's wrong with projects using the $(NugetPackageRoot) property, defined in the nuget-generated *.csproj.nuget.g.props file?

    <NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>

@clairernovotny
Copy link
Author

I don't recall the context, maybe it was from @davkean, but I don't think that's documented and it could be removed or redefined.

@clairernovotny
Copy link
Author

One other thing, that variable isn't available to scripts. The VS DevCmd script that sets up the environment vars should set something as well.

@emgarten
Copy link
Member

The property @AArnott mentioned sounds like what you are asking for. This property isn't used internally, it is there for writing custom targets or for use from a package. It is unlikely this would change.

One other thing, that variable isn't available to scripts. The VS DevCmd script that sets up the environment vars should set something as well.

The default package folder path is user specific, but beyond that this path can be set on a per-project basis, which means there is no right answer apart from where the project lists as the packages folder. dotnet.exe restore --packages c:\tmp will put them there instead of in the default location. It is also possible to define RestorePackagesPath in the project to override the location. And with fallback folders the packages could be spread out and not in the default user location (.g.props lists these also).

What has been proposed for build scripts your example is to have an MSBuild task that can ensure a package exists, downloading it if needed, and put it in the default packages folder. Then return the path to it. Or search known package locations and find it, and give you the path. #5919

@clairernovotny
Copy link
Author

@emgarten if that property is going to be stable, I'm happy to use it and the script issue can be dealt with separately.

@emgarten emgarten added this to the 4.6 milestone Dec 12, 2017
@emgarten emgarten added Functionality:Restore Resolution:Question This issues appears to be a question, not a product defect labels Dec 12, 2017
@emgarten
Copy link
Member

It is stable 🍰

@vpenades
Copy link

vpenades commented Jul 10, 2018

Sorry for commenting on a closed issue: $(NugetPackageRoot) is not as consistent as it might seem...

We've found that in most cases, it points to C:\Users\*user*\.nuget\packages\ but in a few others it points to C:\Temp\.nuget\packages Notice the missing slash in the second case. This detail is causing us some headaches.

@AArnott
Copy link
Contributor

AArnott commented Jul 10, 2018

You can use the msbuild function EnsureTrailingSlash to help you.

@Joev-
Copy link

Joev- commented Jan 16, 2019

Apologies also for the necro on this issue, but I am also suddenly facing inconsistencies with $(NugetPackageRoot).

Our build agent is generating a value that is missing the trailing slash, running VS2017 15.9.5. I am not against using an MSBuild function if it turns out to be really necessary, but I would like to understand why this is happening suddenly. Any clues are much appreciated as the agent is fairly vanilla and I'm at a loss of what could have changed.

Edit: I've narrowed this down to our build agent being switched to running under the system account rather than a user account. Why would the system account cause the trailing slash to not appear for this specific property?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Restore Resolution:Question This issues appears to be a question, not a product defect
Projects
None yet
Development

No branches or pull requests

5 participants