-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1059.ps1
More file actions
305 lines (257 loc) · 10.9 KB
/
Copy path1059.ps1
File metadata and controls
305 lines (257 loc) · 10.9 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#-------------------------------------------------------------------------
# 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
[String]
$Outdir = "C:\Application\CSR"
)
Begin
{
$MSBUILD="c:\WINDOWS\Microsoft.NET\Framework\v3.5\MsBuild"
$WEBPROJECTOUTPUTDIR="$OUTDIR\CSRWeb"
$script:Log=@()
#-------------------------------------------------------------------------
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
{
Write-Debug "Starting CreateWorkspace"
Function DeleteWorkspace
{
# Delete the workspace if it exists.
Write-Verbose "Deleting workspace (if exists): $workspaceName"
$log += "Deleting workspace (if exists): $workspaceName"
&$TF workspace /delete $workspaceName /noprompt | out-null
Write-Verbose "Done deleting workspace."
$log += "Done deleting workspace."
} #END DeleteWorkspace
}
Process
{
DeleteWorkspace
# Create the folder
if (! (Test-Path $CSRDIR))
{
Write-Verbose "Creating folder: $CSRDIR"
$log += "Creating folder: $CSRDIR"
new-item -itemtype directory -path $CSRDIR -force | out-null
Write-Verbose "Completed Creating folder: $CSRDIR"
$log += "Completed Creating folder: $CSRDIR"
}
# Move to folder
cd $CSRDIR
# Create the workspace
Write-Verbose "Creating workspace: $workspaceName"
$log += "Creating workspace: $workspaceName"
&$TF workspace /new /computer:$computerName /server:$TFsServer /noprompt $workspaceName
Write-Verbose "Done Creating workspace: $workspaceName"
$log += "Done Creating workspace: $workspaceName"
# Get the latest
Write-Verbose "Getting the latest code from: $TFsServer. This could take awhile..."
$log += "Getting the latest code from: $TFsServer. This could take awhile..."
&$TF get $/CSR/CSR /recursive
Write-Verbose "Done getting latest."
$log += "Done getting latest."
Write-Verbose "Tree initialization is complete."
$log += "Tree initialization is complete."
}
End
{
Write-Debug "CreateWorkspace Complete"
}
} #END CreateWorkspace
#-------------------------------------------------------------------------
# Get Next Label
#
# Labels are BL{major}.{minor}
# major = 1 - ???
# minor = 001 - 999
#-------------------------------------------------------------------------
Function GetNextLabel()
{
Begin
{
Write-Debug "Starting GetNextLabel"
}
Process
{
$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
write-output $label
}
End
{
Write-Debug "GetNextLabel Completed"
}
}
#-------------------------------------------------------------------------
Function MSBuild($outputdir, $webproject, $project, $ref)
{
Begin
{
Write-Debug "Starting MSBuild"
Write-Debug "outputdir: $outputdir webproject: $webproject project: $project ref: $ref"
}
Process
{
# 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) }
}
End
{
Write-Debug "MSBuild Completed"
}
}
#-------------------------------------------------------------------------
# Create the Label
#-------------------------------------------------------------------------
Function ApplyLabel()
{
Write-verbose "Create the Label"
$log += "Create the Label"
$label = GetNextLabel
&$TF label $label $/CSR/CSR /recursive
&$TF get /version:L$($label)
Write-verbose "Applied label $label"
$log += "Applied label $label"
return $Label
} # END ApplyLabel
} # End Begin
Process
{
trap [Exception]
{
write-verbose "Build Failed"
$log += "Build Failed"
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-Verbose "Building CSRWEB"
$log += "Building CSRWEB"
. MsBuild "$Outdir\CSRWeb\" $WEBPROJECTOUTPUTDIR "$CSRDIR\CSR\CSR\CSRWeb\CSRWeb\CSRWeb.csproj" $REFPATH
# copy-item C:\TFSMAIN\CSR\bin\Microsoft.ApplicationBlocks.Data.dll $CSRDIR\CSRWeb\bin\ -credential
# copy-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll $CSRDIR\CSRWeb\bin\ -credential
# copy-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-verbose "Build CSRWEB Successful"
$log += "Build CSRWEB Successful"
}
{$CSRWS}
{
Write-verbose "Building CSRWS"
$log +="Building CSRWS"
. MsBuild "$Outdir\CSRWS\" $WEBPROJECTOUTPUTDIR1 "$CSRDIR\CSR\CSR\CSRWS\CSRWS\CSRWS.csproj" $REFPATH
# copy-item C:\TFSMAIN\CSR\bin\Microsoft.ApplicationBlocks.Data.dll $CSRDIR\CSRWeb\bin\ -credential
# copy-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll $CSRDIR\CSRWeb\bin\ -credential
# copy-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-verbose "Build CSRWS Successful"
$log += "Build CSRWS Successful"
}
{$CSRServices}
{
Write-verbose "Building CSR Services"
$Log += "Building CSR Services"
. MsBuild "$Outdir\CSRSERVICES\" $WEBPROJECTOUTPUTDIR2 "$CSRDIR\CSR\CSR\CSRSERVICES\CSRSERVICES\CSRSERVICES.csproj" $REFPATH
# copy-item C:\TFSMAIN\CSR\bin\Microsoft.ApplicationBlocks.Data.dll $CSRDIR\CSRWeb\bin\ -credential
# copy-item C:\TFSMAIN\CSR\bin\Microsoft.Practices.EnterpriseLibrary.Caching.dll $CSRDIR\CSRWeb\bin\ -credential
# copy-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-verbose "Build CSR Services Successful"
$Log += "Build CSR Services Successful"
}
} # End Switch
} #End Process
End
{
IF ($LogPath)
{
$log | Out-file -FilePath $LogPath -Encoding ascii -Append
}
} #END End