- Is this possible? I have done a lot of research but I have found nothing so far.
Of course, it is not even WPF related. You can run the dotnet
CLI just like any other program with Process
. The code below will call the help for dotnet
.
var process = new Process();
var startInfo = new ProcessStartInfo
{
FileName = "dotnet.exe",
Arguments = "-h"
};
process.StartInfo = startInfo;
process.Start();
If you do not want do display the console widow, you can add these options to the start info.
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
Keep in mind that commands may fail and you should handle the console output to react on that. Look here for a related post that demonstrates how you can redirect console output.
- Is there a CLI command to add a new class to a class library project? The tool needs to create a new solution that compiles with all classes it creates added to the project.
Let's do a quick walkthrough to show the essential parts of your application. Since it is is always the same code for calling dotnet
but with different arguments, I will only show those.
- Create an new solution with a class library
Arguments = @"new classlib -o C:\The\Path\To\Your\Solution -n MyProject"
The classlib
command will create a class library in the given directory with the name MyProject
.
- Adding a new class
File.Create(@"C:\The\Path\To\Your\Solution\MyClass.cs");
File.WriteAllText(@"C:\The\Path\To\Your\Solution\MyOtherClass.cs", cSharpClassBoilerPlateCode);
As far as I know there is no built-in command to create single class files. However, you can just create a .cs
file with File.Create
or File.WriteAllText
that contains some boilerplate code directly in your project directory. The .NET SDK-style project format includes all source files in the project directory by default, unless you overrode this behavior.
- Compile the project
Arguments = @"build C:\The\Path\To\Your\Solution\MyProject.csproj"
This is only a starter example. The dotnet
command line interface offers a lot more options to customize and work with solutions and projects, see below for reference.