'How to write C# code that auto generate new project (.sln) with simple 'hello world' method?

I looked at some examples and I didn't find any example that create new .sln with one simple runnable class (simple console project with main that print hello world)

anyone know how to do it or can point on some example ?



Solution 1:[1]

You can easily use CLI

    dotnet new console -n MyConsoleApp
    cd MyConsoleApp
    echo "Console.WriteLine(\"Hello, David\");" > Program.cs  //OSX
    echo 'Console.WriteLine("Hello, David");' > Program.cs;   //Windows
    dotnet run

You can run the above code in one line:

OSX:

dotnet new console -n MyConsoleApp && cd MyConsoleApp && echo "Console.WriteLine(\"Hello, David\");" > Program.cs && dotnet run

Windows

dotnet new console -n MyConsoleApp; cd MyConsoleApp; echo 'Console.WriteLine(\"Hello, David\");' > Program.cs; dotnet run

enter image description here enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1