简体   繁体   中英

Automate Creating Visual Studio Project

I would like to automate the process of creating a Visual Studio 2013 project (specifically, an MVC 4 web application) via a powershell script and I am not finding any useful information on how to do this.

I understand I could take a the project template xml/scaffolding files and copy them and replace the namespace/project tokens etc, however VS does all of this perfectly already so it seems there should be an API that could be used to do so.

Sometimes I see references to an old tool called projectgen.exe that seems to be a VS 2008 artifact - I cannot find it for VS 2013, and I'm not even sure if it actually does what I'm after.

One way to do it is to have Visual Studio do it for you, using automation .

The code should look something like:

{
    Type type = Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
    var visualStudio = Activator.CreateInstance(type, true);

    var dte = visualStudio.Instance;
    var solution = (Solution2)dte.Solution;
    solution.Create(destinationFolder, solutionName);
    string templateFile = solution.GetProjectTemplate(applicationProjectTemplateName);
    var project = solution.AddProjectFromTemplate(projectName, DestinationFolder, templateFile);
    visualStudio.SaveAll();
}

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