modec
modec

Reputation: 213

How do I resolve the NuGet repository path via code?

I'm writing a NuGet package that needs to execute an .exe stored in the package itself.

I do not want to use content (and content and scripts are going away anyway)

So I want to be able to find the path to where my package is stored. How do I do that reliably now that the package folder can be changed by the user and nuget.config can be stored on multiple levels?

It is mentioned here: http://blog.nuget.org/20150729/Introducing-nuget-uwp.html .. " Simply find it from the .nuget path ..."

But there must be a utility for doing that right? Maybe one of the Nuget-libraries can resolve the path for me?

Upvotes: 3

Views: 409

Answers (1)

Yishai Galatzer
Yishai Galatzer

Reputation: 8862

There is no public api (properly support at least) to do it. But you could use the NuGet.Configuration from the myget feed - https://www.myget.org/gallery/nugetbuild

Create a settings object using this API -

var settings = Settings.LoadDefaultSettings(rootFolder, null, null);

See https://github.com/NuGet/NuGet3/blob/dev/src/NuGet.Configuration/Settings/Settings.cs#L114

You might need to tweak the input to get it right, I didn't try it in a unit test.

Then get the global packages folder

 var path = SettingsUtility.GetGlobalPackagesFolder(settings)

Note that the packages is not in a stable form, and I expect changes going forward, at least after addressing this bug - https://github.com/NuGet/Home/issues/1098

Edit -

You can now just grab the package from nuget.org

Upvotes: 1

Related Questions