[英]Programmatically with C# code restore PackageReferences
I'm trying programmatically with C# base code to restore packageReference for .NET framework & .NET core projects.我正在尝试使用 C# 基本代码以编程方式恢复 .NET 框架和 .NET 核心项目的packageReference 。
I thought about using dotnet.exe / msbuild.exe but I don't know how!我想过使用 dotnet.exe / msbuild.exe 但我不知道如何使用!
I want to simulate what we can do with dotnet CLI :我想模拟我们可以用dotnet CLI做什么:
dotnet restore '.\myproject.csproj' --packages '.\OutputFolder'
but I want to do it programmatically.但我想以编程方式进行。
Thanks for the answers.感谢您的回答。
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.