简体   繁体   中英

How can I find nuget package installation folder programmaticaly ? (.NET Core - Cross Platform)

Is there anyway for find .nuget folder and all related folders ? such as

  1. C:\\Users\\ ... \\.nuget
  2. C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\1.1.0

but should be programmatically , Cross platform way , compatible with .NET Core

My problem is finding path of

  1. mscorelib.dll and System.Runtime.dll
  2. custom installed assemblies like Microsoft.EntityFrameworkCore.Relational.dll

for working with Roslyn in .NET Core I need to reference them as list of MetadataReference.

MetadataReference.CreateFromFile(...)

so I think If I know about all .nuget directories. I can search into them.

You can get the path to your .nuget folder programmatically by using this NuGet package like this:

ISettings settings = Settings.LoadDefaultSettings(null);
string nugetPath = SettingsUtility.GetGlobalPackagesFolder(settings);

There is no specific way to get the NuGet location. You can get the user profile location like below.

Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

And get ProgramFiles location like below.

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)

Append the remaining path by hard coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM