我正在尝试为我正在安装的另一个应用程序启用 dotnet 3.5 依赖项。问题是我正在使用的 cmd shell 抛出此错误“'dism' 未被识别为内部或外部命令、可运行程序或批处理文件。” 但是如果我复制并粘贴要传递给 cmd shell 的字符串:
Dism /online /LogPath:C:\Users\HollyPlyler\source\repos\installerOptimized\installerOptimized\bin\Debug\\Logs\DSIMEnableDotNet.log /LogLevel:4 /Enable-Feature /FeatureName:NetFx3
它工作正常。
这是我的 CMD 课程:
class CommandLineTool
{
public async Task Com(String command, string logName)
{
Console.WriteLine("received " + command);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.FileName = "CMD.exe";
startInfo.Arguments = "/c " + command;
process.StartInfo = startInfo;
Task t = Task.Run(()=>process.Start());
t.Wait();
string output = process.StandardOutput.ReadToEnd();
Console.BackgroundColor = ConsoleColor.Black;
if (output.Contains("0/1"))
{
Console.ForegroundColor = ConsoleColor.Yellow;
installerOptimized.install.success = false;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
installerOptimized.install.success = true;
}
Console.WriteLine(output);
string success = installerOptimized.install.success ? "successful" : "unsuccessful";
System.IO.File.WriteAllLines("Logs/" + logName +"_" + success + ".txt", output.Split('\n'));
process.WaitForExit();
}
}