Reputation: 1124
From Visual Studio I can build several projects grouped by solution folder by right click -> Build.
Is there any command line / power shell alternative for that?
Upvotes: 5
Views: 13472
Reputation: 19830
In the screenshot above just do following:
cd [directory with WindowsFormsApplication1.sln]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
Powershell is just "console". For building sln or csproj you need to msbuild.exe which is a tool for building .NET projects
If you want only to build one solution folder from sln it is not so easy because folders in Visual Studio are virtual and you need to parse sln file to find folders
Update
The following code will parse sln file and run msbuild for project which belongs to folder:
param([string]$slnPath=".\YourSLN.sln", [string]$VsFolderName="Your_folder")
$slnContent = Get-Content $slnPath
$folderLine = $slnContent | ?{$_.Contains("2150E333-8FDC-42A3-9474-1A3956D46DE8")} | ?{$_.Contains($VsFolderName)}
$guid = $folderLine.Split(", ")[-1].Replace('"',"")
#Write-host $guid
$csprojGuids = $slnContent | ?{$_.Contains("= "+$guid)} | %{$_.Split("=")[-2].Trim()}
#Write-Host $csprojGuids
for($i=0; $i -lt $csprojGuids.count; $i++){
$toFind = $csprojGuids[$i]
$def = $slnContent | ?{$_.Contains("Project")} | ?{$_.Contains($csprojGuids[$i])} | %{$_.Split(",")[-2].Trim().Replace('"','')}
Write-Host "building" $def
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe $def
}
Upvotes: 6
Reputation: 3239
You can use DTE to get paths of projects and then pass them to msbuild. Run this from Package Manager Console (presuming msbuild is in your %path%):
project|% dte|% solution|? projectname -eq NewFolder1|% projectitems|% object|% {msbuild $_.fullname}
Upvotes: 1