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

プロジェクトを作成するには、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 に答える
0

Jim Christopher によるhttp://studioshell.codeplex.com/をチェックしてください。

于 2014-07-29T13:15:05.613 に答える