C# 如何运行dotnetnew命令并直接在代码中创建新项目
因此,我想直接从我的c#代码创建新的dotnet项目,大概是通过运行C# 如何运行dotnetnew命令并直接在代码中创建新项目,c#,templates,.net-core,dotnet-cli,C#,Templates,.net Core,Dotnet Cli,因此,我想直接从我的c#代码创建新的dotnet项目,大概是通过运行dotnet new命令或类似的东西,但我找不到它的语法。我在谷歌搜索到的几乎所有内容都提供了如何通过VSGUI或CLI创建项目的方法,只需讨论一次 我尝试了一些类似这样的不同迭代,但没有成功。它只是在运行waitforexit线路后挂起。这是大概的,还是有更好的办法 var流程=新流程 { StartInfo=新流程StartInfo { FileName=“cmd.exe”, 参数= @ $“dotnet新基金会-N Hel
dotnet new
命令或类似的东西,但我找不到它的语法。我在谷歌搜索到的几乎所有内容都提供了如何通过VSGUI或CLI创建项目的方法,只需讨论一次
我尝试了一些类似这样的不同迭代,但没有成功。它只是在运行waitforexit线路后挂起。这是大概的,还是有更好的办法
var流程=新流程
{
StartInfo=新流程StartInfo
{
FileName=“cmd.exe”,
参数= @ $“dotnet新基金会-N HeloAPiWorl - E”“你好”“-EN”“Hello”“-LA”“H”“”
重定向标准输出=真,
RedirectStandardError=true,
UseShellExecute=false,
CreateNoWindow=false,
WorkingDirectory=@“C:\testoutput”
}
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
您正在使用cmd.exe作为启动进程,它不会自动结束执行。我不确定您用于创建新项目的模板
请直接使用DotNet cli执行命令,以便在执行完成后自动关闭
尝试使用下面的示例使用控制台模板创建一个新项目
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = @$"new console -o myApp",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = false,
WorkingDirectory = @"C:\testoutput"
}
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
您正在使用cmd.exe作为启动进程,它不会自动结束执行。我不确定您用于创建新项目的模板 请直接使用DotNet cli执行命令,以便在执行完成后自动关闭 尝试使用下面的示例使用控制台模板创建一个新项目
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = @$"new console -o myApp",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = false,
WorkingDirectory = @"C:\testoutput"
}
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
成功了!没有意识到这就是filename属性的用途。干杯该命令是一个自定义模板,我正在构建它!没有意识到这就是filename属性的用途。干杯该命令是我正在构建的自定义模板