6

From Visual Studio I can build several projects grouped by solution folder by right click -> Build.

Solution folder build command

Is there any command line / power shell alternative for that?

1
  • msbuild.exe is your friend, isn't it? Commented Dec 10, 2014 at 9:19

2 Answers 2

6

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

there are several hundreds of projects in the solution, that's why I need to scope the build to one particular folder to speed up the process.
1

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}

4 Comments

that's exactly what I need, but is there any chance to run it outside of Visual Studio?
@VladimirSachek Take a look at StudioShell, otherwise you can access DTE from outside of VS without any special extension. I have some C# code for it, so let me know in case StudioShell won't work.
@MarkToman StuidioShell link is dead. Is this still a thing? Where's your C# code?
@not2qubit The OP asked for PowerShell, not C#. As for the rest, I’ve been on a different stack for 5+ years, so no idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.