Skip to content

Instantly share code, notes, and snippets.

@taisyo7333
Last active August 28, 2015 04:40
Show Gist options
  • Save taisyo7333/a54965885592d785a96e to your computer and use it in GitHub Desktop.
Save taisyo7333/a54965885592d785a96e to your computer and use it in GitHub Desktop.
VisualStudio BuildScript by powershell
<#
.SYNOPSIS
Build MS project(.sln)
.DESCRIPTION
Build Microsoft Visual Studio project (.sln)
.PARAMETER project
The project file to build.
.PARAMETER type
The kind of type to build.
'CLEAN' : clean
'BUILD' : compile
'REBULD': CLEAN and then BUILD
.PARAMETER config
The configuration of project solution to build.
'Release'
'Debug'
.EXAMPLE
.\Build.ps1 -project ".\abc.sln" -type 'Rebuild' -config 'Debug'
.EXAMPLE
.\Build.ps1 -project .\xyz.sln -type Rebuild -config Release
.LINK
MSBuild Command-Line Reference
https://msdn.microsoft.com/ja-jp/library/ms164311.aspx
.NOTES
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)][string]$project = '',
[Parameter(Mandatory=$true)][ValidateSet('Rebuild','Build','Clean')] [string]$type,
[Parameter(Mandatory=$True)][ValidateSet('Release','Debug')] [string]$config
)
$ms_build_path = 'C:\Windows\Microsoft.NET\Framework\v4.0.30319;'
$env:Path = $env:Path + ';' + $ms_build_path
#MSBuild $project /t:Rebuild /p:Configuration=Release /m
$command = "MSBuild $project /m /t:$type /p:Configuration=$config"
function Get-LogFileName
{
param
(
)
# timestamp + "$type + $config + .log"
$timestamp = Get-Date -Format yyyyMMdd_HHmmss
$filename = $timestamp + "_" + $config + "_" + $type + ".log"
return $filename
}
$log_folder = "log"
if( ( Test-Path $log_folder ) -ne $true )
{
New-ITem -name $log_folder -ItemType directory
}
$log_filename = Get-LogFileName
$log_path = $log_folder + "\" + $log_filename
# Excetute $command as command
Invoke-Expression $command | Tee-Object -FilePath $log_path -Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment