2

I'm trying to automate some of the tasks I perform on each web project. What I want is a PoSH script that I can run on a new solution that will:

  • load the solution contained in the scripts current directory.
  • create new projects for the loaded solution and add them to the solution.
  • create some classes and add them to each of the projects.

So far I have a simple script (shown below) that finds and opens the local solution file.

$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Set-Location $dir

$solution = Get-ChildItem | Where-Object{($_.Extension -eq ".sln")}

if ($solution.Count -eq 0)
{
    "Please place this script in the folder containing you solution file."
    break;
}

$dteObj = New-Object -ComObject "VisualStudio.DTE"
$dteObj.Solution.Open($solution.FullName)

How can I now create new projects and add them to the solution?

4

2 回答 2

0

查看Jim Christopher 的http://studioshell.codeplex.com/

于 2014-07-29T13:15:05.613 回答
0

要创建项目,请调用 GetProjectTemplate,然后将返回的模板路径传递给 AddFromTemplate。

在包管理器控制台中试试这个。

    #Create a Console Project
    $csTemplatePath = $dte.Solution.GetProjectTemplate("ConsoleApplication.zip", "CSharp")
    $csPrjPath = "C:\\Projects\\SolutionName\\ConsoleApplication1"
    $dte.Solution.AddFromTemplate($csTemplatePath, $csPrjPath, "ConsoleApplication1", 'false')

    #Create a C# class
    $itemPath  = $dte.Solution.GetProjectItemTemplate("Class.zip", "CSharp")
    $prj = Get-Project
    $prjItem = $prj.ProjectItems.AddFromTemplate($itemPath, "Project.cs")
于 2015-06-22T12:46:10.487 回答