简体   繁体   中英

How to call “dotnet new” in C#

What I want is creating a new Winforms project using dotnet new , and I have tried the following code but not worked.

ProcessStartInfo psi = new ProcessStartInfo();
//psi.FileName = "cmd.exe";
//psi.Arguments = @"/C cd C:\Users\Administrator\Desktop\test & dotnet new winforms –n Test1";
psi.FileName = "dotnet.exe";
psi.Arguments = @"/C dotnet new winforms –-name Test3";
Process p = Process.Start(psi);

在此处输入图像描述

In addition, how to specify the location of the new project, such as C:\Users\Administrator\Desktop\test

Try the following:

Process p = Process.Start("dotnet", "new winforms --name Test3 --output C:\\Users\\Administrator\\Desktop\\test");

Process.Start with arguments Documentation

Dotnet new documentation for the -o |--output flag

Also make sure that you are running with the right permissions to access the folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM