'How do I generate a project template within code?

I'm currently working on an ASP.NET Core Web API. One of my scenarios looks like this: the user selects a certain project type/language. Lets say the user selects Python or C#, meaning the user wants to create a Python or C# project template. Is it possible/is there an easy way to create such a project template within the code or would I have to create all files manually in the code? This is actually simply simulating the scenario when a user wants to create a new project in Visual Studio where he selects a template from the create a new project menu, its just that I want to do this with my own service.



Solution 1:[1]

For .NET: I would make use of the dotnet new cli tool, and use the ProcessStartInfo together with the Process.Start.

For Python, I would do the same, but require the intallation of pyscaffold.

Solution 2:[2]

You can use an embedded resource which is e.g. a ZIP file that contains all the files you need to make a project. You can then extract the ZIP file in your code. That way you can simply update the ZIP file in case you want to add something or update to a newer version of Visual Studio.

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 mslot
Solution 2 Thomas Weller