Reputation: 225
I want to restore nuget packages programmatically for .net core and .net Framework based on Packages.config
& package references.
Any idea?
Thank you!
Upvotes: 1
Views: 1131
Reputation: 1853
If using shell is ok, You may try following steps to restore nuget packages using c#.
public static void RestorePackages(string solutionPath)
{
var dir = AppDomain.CurrentDomain.BaseDirectory;
ProcessStartInfo objPI = new ProcessStartInfo($"{dir}\\nuget.exe", $"restore \"{solutionPath}\" -Verbosity quiet");
objPI.RedirectStandardError = true;
objPI.RedirectStandardOutput = true;
objPI.UseShellExecute = false;
Process objProcess = Process.Start(objPI);
string error = objProcess.StandardError.ReadToEnd();
string output = objProcess.StandardOutput.ReadToEnd();
objProcess.WaitForExit();
}
Upvotes: 0
Reputation: 1866
The nuget.exe tool deals with both cases. So instead of "msbuild /t:Restore" or "dotnet restore", just run "nuget restore". If you want to do it programatically, you can use the nuget package Nuget.CommandLine (install via Nuget or Chocolatey, depending on your needs)
Upvotes: 1