-
Notifications
You must be signed in to change notification settings - Fork 0
/
posh-msbuild.psm1
129 lines (103 loc) · 5.5 KB
/
posh-msbuild.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<#
.SYNOPSIS
Build support for daptiv product
#>
Import-Module $PSScriptRoot\load-EnvironmentVariables.psm1
[String] $Global:MsBuildExe
function find-ToolsDir
{
param([string] $frameWorkDir, [string] $frameworkVersion)
if([string]::IsNullOrEmpty($frameWorkDir))
{
$FrameworkDir = $env:frameworkDir
}
if([string]::IsNullOrEmpty($frameworkVersion))
{
$frameworkVersion = $env:FrameworkVersion
}
$toolsDir=[System.IO.Path]::Combine($frameWorkDir, $frameworkVersion)
return (Resolve-Path $toolsDir).Path
}
function find-MsBuild
{
param([string] $frameWorkDir, [string] $frameworkVersion)
$toolsDir= (find-ToolsDir -frameWorkDir $frameWorkDir -frameworkVersion $frameworkVersion)
$msbuild = [System.IO.Path]::Combine($toolsDir, "msbuild.exe")
write-host "Using msbuild at $msbuild"
if ($msbuild -eq $Null -or !(Test-Path $msbuild))
{
throw ("msbuild.exe not found for " + $frameworkVersion)
}
return $msbuild
}
function IsNetFx2Installed
{
return (![String]::IsNullOrEmpty($env:VS90COMNTOOLS));
}
function IsNetFx35Installed
{
return (!([String]::IsNullOrEmpty($env:VS90COMNTOOLS) -or [String]::IsNullOrEmpty($env:Framework35Version)) )
}
function IsNetFx4Installed
{
return (![String]::IsNullOrEmpty($env:VS100COMNTOOLS));
}
function IsNetFx45Installed
{
return (![String]::IsNullOrEmpty($env:VS110COMNTOOLS));
}
function import-VariablesFromVs
{
<#
.SYNOPSIS
Load variables from a visual studio command prompt
.PARAMETER platform
A supported platform, one of
x86
amd64
x64
ia64
x86_amd64
x86_ia64
.PARAMETER $toolsDir
The visual studio tools directory
#>
param([string] $platform="x86", [string] $toolsDir=$env:VS110COMNTOOLS)
$batchFile = Resolve-Path ([System.IO.Path]::Combine("$toolsDir..\..\vc", "vcvarsall.bat"))
invoke-cmdScript -script $batchFile -parameters $platform
Write-Host @"
Visual Studio Powershell
Variables loaded from $batchFile
"@
[System.Console]::Title = "Visual Studio PowerShell"
}
function import-VariablesFromVSLatest
{
<#
.SYNOPSIS
Load variables from latest available visual studio command prompt
.PARAMETER platform
A supported platform, one of
x86
amd64
x64
ia64
x86_amd64
x86_ia64
#>
param([string] $platform="x86")
if (IsNetFx45Installed)
{
import-VariablesFromVs -platform $platform -toolsDir $env:VS110COMNTOOLS
}
elseif( IsNetFx4Installed )
{
import-VariablesFromVs -platform $platform -toolsDir $env:VS100COMNTOOLS
}
else
{
throw "These build scripts only support .net fx 4"
}
}
import-VariablesFromVSLatest
$Global:MsBuildExe = find-msbuild