Generate c# solution template - c#

I want to create a VS2010 c# solution template generator and I'm looking for free/open tools to achieve this.
An example of what I'm trying to do is a winform application takes project name, namespace and database connectionstring and produce a c# customized solution with my custom classes, namespace and references.
I found those:
EnvDTE
Code Generation and T4 Text Templates
Is this the right way to do this? Do you know better tools?

You need to look at project templates. Normally you only get prompted for a project name (used as the solution name as well if creating a solution at the same time).
However the project template system can run code (as seen with C++ and ASP.NET MVC Projects).
There is a lot of information in the VS SDK, but you might find examining project templates that launch wizards useful to isolate the useful bits of documentation.

Related

Creating a Visual Studio project from command line or powershell

I have a quite huge solution and I've to perform some maintenance (creating test classes for whole projects and so on) and I was wondering if it's possible with powershell or vscode to create projects automatically. I've just followed this link and tried to use the IVSSolution interface from powershell but with no luck. Is there a working and simplier solution?
While, I'm not sure your requirements, I think what you should be really looking for is Project Templates.
This blog explains the process of creating a project template in details. Or, You can, create a project template using PowerShell.

How to create a Custom Scaffolding in multiple projects (mvc + class libraries)

I have a project consisting of few projects (one MVC Application and 3 class libraries for business logic and data access).
I am new to building scaffolding extension and was wondering if I can create a Custom Scaffolder which can generate
Controller, ViewModel and Views in my MVC Application Project
Add some files and folders in Other Projects, that are of type Class Library.
Until now, I have achieved the 1st target (it was fairly easy) but I am unable to find any method to add files to other projects.
I was wondering if there is no direct way of doing it, maybe I can just navigate to the folders in the directories of other projects and create the files. Then include them in my project manually.
P.S. I am using the basic scaffolder template by SideWaffle
Thanks for all the answers in advance.
Sorry, but this extension is no longer available, I have discontinued it
I created an extension for Visual Studio that lets you accomplish this with T4 Templates. You should be able to hit both targets but for number one you will need to do some extra work. I don't integrate with existing scaffolding stuff so you will have to write your own but my extension makes it easy. Its up on Visual Studio gallery and I have a demo/training video you can watch to see how to generate multiple files across multiple projects. Full disclaimer, I charge for this but do offer a free community version.

Create Solution/Project programmatically without Visual Studio

I would like to create a Visual Studio Solution and a C# Project programmatically, but without a instance of Visual Studio installed on the machine.
Scenario
I am trying to build a "engine" that will read some metadata in a SQL database and transform them into a UI. The database will be maintained by another people with a Web or WCF interface and I want the Server Application frequently (by schedule or pressing a button) use this informations to create autommaticaly a new version of the software (create solution -> project -> build -> create deployment).
So, I searched about programmatically create Solution and I found only the Automation Model in VS, it's about use an Add-In Project and this don't serves for my propose.
Perhaps I was a little confused in my explanation, so ask me more especific details, so I can be more accurate :)
Thanks for help
I think generating the solution is a little extreme.
The solution file structure hasn't changed much since 2005 http://msdn.microsoft.com/en-us/library/bb165951(v=VS.80).aspx, and there are a few projects trying to automate their generation, like Premake https://bitbucket.org/premake.
However, the kind of scenario you describe, might be I believe (better?) adressed with t4 templates http://msdn.microsoft.com/en-us/library/vstudio/bb126445.aspx, or only project file generation.
What you are describing is possible to do in C# Windows app but tedious and difficult. I remember seeing VB6.0 app like that but here i would suggest you look into WPF. Still it's C# programming but WPF can load dynamically a "window" from a string or a file if you want.

Easiest way to programmatically add files to a project

I want to programmatically add class files to a c# project. Right now I'm thinking the fastest route may be to simply edit the xml file directly but I know there are api's for working with the project.
The thing is that I want to run an exe that just updates the file. I don't want to have to have the target project open in Visual Studio which is what it seems like is necessary with the automation interfaces used by add-ins.
So does anyone know how to do this with an api or am I stuck with working directly with the xml?
There is comprehensive support for T4 files which allow you programmatically generate files in the project, good example is Entity Framework templates for Self-Tracking entities and POCO, which you can get in the VS Gallery.
Also there are several good editors for T4 which allow you to have intellisence while editing templates

Is it possible to add a New Project Wizard with a VSPackage?

I have a VSPackage for Visual Studio 2008 that I created for adding some editor and custom language functionality. I also have a need to add a new project/solution wizard to create a new Solution and a complex series of C++ projects to the solution. I know I can do this using a "Custom Wizard", but I would be much happier if I can implement this within my VSPackage using C# instead.
So I guess the main question is, is it possible to add an entry to the Project Types dialogs in Visual Studio from a VSPackage? Or is the "Custom Wizard" and JScript my only option here?
And if it's possible, where can I find information and/or samples on how to accomplish this?
To add an entry to the Project Types dialog, you need to install a project template (a zip file containing a .vstemplate file) as part of your installation. You will want to do this from your setup routine rather than from the VSPackage itself.
However, your .vstemplate can invoke a wizard written in C#. Although this is indeed a "custom wizard," you can provide a reference to a .NET assembly. There is no need to use a scripting language.
For an example, see IronPython > C# Example.IronPythonProject in the VS2008 SDK browser. Unfortunately this demonstrates only limited wizard functionality and only for project items rather than projects, but I hope it will be useful all the same.

Categories