-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1056.ps1
More file actions
260 lines (213 loc) · 9.52 KB
/
Copy path1056.ps1
File metadata and controls
260 lines (213 loc) · 9.52 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#-------------------------------------------------------------------------
# Script that will:
# 1. Create a workspace. Workspacce Name: _Root
# 2. Get the latest code from repository
#-------------------------------------------------------------------------
Param(
[switch]
$CSRWEB,
[switch]
$CSRWS,
[switch]
$CSRServices,
[string]
$LogPath
)
Begin
{
If ($LogPath)
{
IF (-NOT (Test-Path $LogPath))
{
throw "Log Path:$($LogPath) not found!"
}
}
$MSBUILD="c:\WINDOWS\Microsoft.NET\Framework\v3.5\MsBuild"
$WEBPROJECTOUTPUTDIR="$OUTDIR\CSRWeb"
$SCRIPT:Outdir = "C:\Application\CSR";
#-------------------------------------------------------------------------
Function SetTFS
{
$SCRIPT:tfsServer = "172.29.4.179"
$script:userName = [system.environment]::UserName;
$script:computerName = [system.environment]::machinename
$script:workspaceName = $computerName + "_" + $userName +"_WS" #Use 'WS' as an acronym for "WorkSpace"
$script:CSRDIR = "C:\Brassring2\Application\";
$script:WEBPROJECTOUTPUTDIR="$Outdir\CSRWeb"
$script:WEBPROJECTOUTPUTDIR1="$Outdir\CSRWS"
$script:WEBPROJECTOUTPUTDIR2="$Outdir\CSRServices"
$script:REFPATH="referenceToAllAssembiesUsedInTheProjectSeperatedbySemiColon"
$script:MSBUILD="c:\WINDOWS\Microsoft.NET\Framework\v3.5\MsBuild"
$script:failed = $false
# Set up the TF Alias
# Find where VS is installed.
$key = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\VisualStudio\9.0
$dir = [string] (Get-ItemProperty $key.InstallDir)
$script:tf = "$dir\tf.exe"
} # End SetTFS
#-------------------------------------------------------------------------
Function CreateWorkspace
{
Begin {
Function DeleteWorkspace
{
# Delete the workspace if it exists.
echo "Deleting workspace (if exists): $workspaceName" | Tee-Object -Variable Log
&$TF workspace /delete $workspaceName /noprompt | out-null
echo "Done deleting workspace." | Tee-Object -Variable Log
} #END DeleteWorkspace
}
Process {
DeleteWorkspace
# Create the folder
if (! (Test-Path $CSRDIR)) {
echo "Creating folder: $CSRDIR" | Tee-Object -Variable Log
new-item -itemtype directory -path $CSRDIR -force | out-null
echo "Completed Creating folder: $CSRDIR" | Tee-Object -Variable Log
}
# Move to folder
cd $CSRDIR
# Create the workspace
echo "Creating workspace: $workspaceName" | Tee-Object -Variable Log
&$TF workspace /new /computer:$computerName /server:$TFsServer /noprompt $workspaceName
echo "Done Creating workspace: $workspaceName" | Tee-Object -Variable Log
# Get the latest
echo "Getting the latest code from: $TFsServer. This could take awhile..." | Tee-Object -Variable Log
&$TF get $/CSR/CSR /recursive
echo "Done getting latest." | Tee-Object -Variable Log
echo "Tree initialization is complete." | Tee-Object -Variable Log
}
} #END CreateWorkspace
#-------------------------------------------------------------------------
# Get Next Label
#
# Labels are BL{major}.{minor}
# major = 1 - ???
# minor = 001 - 999
#-------------------------------------------------------------------------
Function GetNextLabel()
{
$major = 1
$minor = 1
$list = (&$TF labels /format:brief |? { $_ -notmatch "-.+" -and $_ -notmatch "Label.+Owner.+Date"})
if ($list -ne $null) {
# Split label into major minor
$major,[int]$minor= (($list | Select-Object -last 1).split()).split(".")
# Increment minor label
$minor++
# Remove BL from string, and cast to int
[int]$major = $major.substring(2)
# If minor gt 999 increment major and reset minor
if ($minor -gt 999) {
$major++
$minor = 1
}
}
# return label
$label = "BL{0}.{1:000}" -f $major, $minor
return $label
}
#-------------------------------------------------------------------------
Function MSBuild($outputdir, $webproject, $project, $ref)
{
# I think this can be cleaned up with where-object, but it's too important to play with
$failed = $false
&$MSBUILD /p:Configuration=Release /p:OutDir=$Outputdir /p:WebProjectOutputDir=$webproject $project |% {
if ($_ -match "Build FAILED") { $failed = $true } ; $_
}
if ($failed) { throw (new-object NullReferenceException) }
$failed = $false
&$MSBUILD /p:Configuration=Release /t:ResolveReferences /p:OutDir=$Outputdir\bin\ /p:ReferencePath=$ref $project |% {
if ($_ -match "Build FAILED") { $failed = $true } ; $_
}
if ($failed) { throw (new-object NullReferenceException) }
}
#-------------------------------------------------------------------------
# Create the Label
#-------------------------------------------------------------------------
Function ApplyLabel()
{
Write-Host "Create the Label" | Tee-Object -Variable Log
$label = GetNextLabel
&$TF label $label $/CSR/CSR /recursive
&$TF get /version:L$($label)
Write-Host "Applied label $label" | Tee-Object -Variable Log
return $Label
} # END ApplyLabel
} # End Begin
Process
{
trap [Exception]
{
write-host "Build Failed" | Tee-Object -Variable Log
exit 1;
}
. SetTFS
. CreateWorkspace
. ApplyLabel
IF (!$CSRWS -AND !$CSRWEB -AND !$CSRServices)
{
Write-Debug "No Options Found Setting ALL"
$CSRWS = $TRUE
$CSRWEB = $TRUE
$CSRServices = $TRUE
}
Switch ("")
{
{$CSRWEB}
{
Write-Host "Building CSRWEB" | Tee-Object -Variable Log
MsBuild "$Outdir\CSRWeb\" $WEBPROJECTOUTPUTDIR " $CSRDIR\CSR\CSR\CSRWeb\CSRWeb\CSRWeb.csproj" $REFPATH
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.ApplicationBlocks.Data.dll $CSRDIR\CSRWeb\bin\ -credential
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll $CSRDIR\CSRWeb\bin\ -credential
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.ObjectBuilder.dll $CSRDIR\CSRWeb\bin\ -credential
rm $Outdir\CSRWeb\*.config -recurse
rm $Outdir\CSRWeb\*.pdb -recurse
rm $Outdir\CSRWeb\*.dll -recurse
rm $Outdir\CSRWeb\*.xml -recurse
rm $Outdir\CSRWeb\bin\*.pdb -recurse
rm $Outdir\CSRWeb\bin\*.config -recurse
rm $Outdir\CSRWeb\bin\*.xml -recurse
Write-Host : "Build CSRWEB Successful" | Tee-Object -Variable Log
}
{$CSRWS}
{
Write-Host "Building CSRWS" | Tee-Object -Variable Log
MsBuild "$Outdir\CSRWS\" $WEBPROJECTOUTPUTDIR1 "$CSRDIR\CSR\CSR\CSRWS\CSRWS\CSRWS.csproj" $REFPATH
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.ApplicationBlocks.Data.dll $CSRDIR\CSRWeb\bin\ -credential
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll $CSRDIR\CSRWeb\bin\ -credential
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.ObjectBuilder.dll $CSRDIR\CSRWeb\bin\ -credential
rm $Outdir\CSRWS\*.config -recurse
rm $Outdir\CSRWS\*.pdb -recurse
rm $Outdir\CSRWS\*.dll -recurse
rm $Outdir\CSRWS\*.xml -recurse
rm $Outdir\CSRWS\bin\*.pdb -recurse
rm $Outdir\CSRWS\bin\*.config -recurse
rm $Outdir\CSRWS\bin\*.xml -recurse
Write-Host : "Build CSRWS Successful" | Tee-Object -Variable Log
}
{$CSRServices}
{
Write-Host "Building CSR Services" | Tee-Object -Variable Log
MsBuild "$Outdir\CSRSERVICES\" $WEBPROJECTOUTPUTDIR2 "CSRDIR\CSR\CSR\CSRSERVICES\CSRSERVICES\CSRSERVICES.csproj" $REFPATH
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.ApplicationBlocks.Data.dll $CSRDIR\CSRWeb\bin\ -credential
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll $CSRDIR\CSRWeb\bin\ -credential
# ©-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.ObjectBuilder.dll $CSRDIR\CSRWeb\bin\ -credential
rm $Outdir\CSRSERVICES\*.config -recurse
rm $Outdir\CSRSERVICES\*.pdb -recurse
rm $Outdir\CSRSERVICES\*.dll -recurse
rm $Outdir\CSRSERVICES\*.xml -recurse
rm $Outdir\CSRSERVICES\bin\*.pdb -recurse
rm $Outdir\CSRSERVICES\bin\*.config -recurse
rm $Outdir\CSRSERVICES\bin\*.xml -recurse
Write-Host : "Build CSR Services Successful" | Tee-Object -Variable Log
}
}
} #End Process
End
{
IF ($LogPath)
{
Out-file -InputObject $Log -Encoding ascii
}
} #END End