This project has moved and is read-only. For the latest updates, please go here.
The module builds using the Visual Studio Command Prompt when available in order to support more project types (e.g. XNA projects). When not using the -PassThru switch, it returns $true if the build succeeded, $false if it failed, and $null if we could not determine the build result. It also provides parameters for showing or hiding the build window, and automatically opening the error log when the build fails.

The module simply passes through any MsBuild command-line parameters you supply, so it supports all functionality (e.g. project types, targets, etc.) that you would get by calling MsBuild directly.

Here is an example of how to import the Invoke-MsBuild module into your powershell session and call it:
Import-Module -Name "PathTo_Invoke-MsBuild.psm1"
Invoke-MsBuild -Path "C:\Some Folder\MySolution.sln"

You can download the module here, or get it from the PowerShell Gallery.

Below are more examples of calling the module. For detailed information on the module's parameters, checkout the documentation.

$buildSucceeded = Invoke-MsBuild -Path "C:\Some Folder\MySolution.sln"

if ($buildSucceeded)
{ Write-Host "Build completed successfully." }
{ Write-Host "Build failed. Check the build log file for errors." }

$process = Invoke-MsBuild -Path "C:\Some Folder\MySolution.sln" -PassThru

Invoke-MsBuild -Path "C:\Some Folder\MySolution.sln" -MsBuildParameters "/target:Clean;Build /property:Configuration=Release;Platform=""Mixed Platforms"" /verbosity:Quiet"

Invoke-MsBuild -Path "C:\Some Folder\MyProject.csproj" -ShowBuildWindowAndPromptForInputBeforeClosing -AutoLaunchBuildLog

Invoke-MsBuild -Path "C:\Some Folder\MyProject.vbproj" -BuildLogDirectoryPath "C:\BuildLogs" -KeepBuildLogOnSuccessfulBuilds -AutoLaunchBuildLog

Invoke-MsBuild -Path "C:\Database\Database.dbproj" -P "/t:Deploy /p:TargetDatabase=MyDatabase /p:TargetConnectionString=`"Data Source=DatabaseServerName`;Integrated Security=True`;Pooling=False`" /p:DeployToDatabase=True"

$logPath = Invoke-MsBuild -Path "C:\Some Folder\MyProject.csproj" -BuildLogDirectoryPath "C:\BuildLogs" -GetLogPath

Last edited Jun 26, 2017 at 6:38 AM by deadlydog, version 24