I want to restore nuget packages programmatically for .net core and .net Framework based on Packages.config
& package references.
Any idea?
Thank you!
I want to restore nuget packages programmatically for .net core and .net Framework based on Packages.config
& package references.
Any idea?
Thank you!
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)
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();
}