[英]Restore nuget packages Programmatically (.net core & .net framework)
I want to restore nuget packages programmatically for .net core and .net Framework based on Packages.config
& package references.我想基于
Packages.config
和包引用以编程方式为 .net core 和 .net Framework 恢复 nuget 包。
Any idea?任何的想法?
Thank you!谢谢!
The nuget.exe tool deals with both cases. nuget.exe 工具处理这两种情况。 So instead of "msbuild /t:Restore" or "dotnet restore", just run "nuget restore".
因此,不要运行“msbuild /t:Restore”或“dotnet restore”,只需运行“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)
如果您想以编程方式执行此操作,可以使用 nuget 包 Nuget.CommandLine(通过 Nuget 或 Chocolatey 安装,具体取决于您的需要)
If using shell is ok, You may try following steps to restore nuget packages using c#.如果使用shell没问题,您可以尝试按照以下步骤使用c#恢复nuget包。
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.