forked from AutoMapper/AutoMapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.ps1
257 lines (217 loc) · 9.45 KB
/
template.ps1
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
properties {
$projectName = "CodeCampServer"
$base_dir = resolve-path .
$build_dir = "$base_dir\build"
$package_dir = "$build_dir\package"
$package_file = "$base_dir\latestVersion\" + $projectName +"Package.exe"
$source_dir = "$base_dir\src\"
$test_dir = "$build_dir\test\"
$result_dir = "$build_dir\results\"
$buildNumber = 99
$databaseName = $projectName
$databaseServer = ".\SqlExpress"
$databaseScripts = "$source_dir\Database"
}
task default -depends Clean, CommonAssemblyInfo, Database, Compile
task privateBuild -depends default, Test
task integrationBuild -depends default, Test,Inspection, Package
<#
Poke HIbernate Config
Create Database Migration
#>
task CreateSolutionTemplate {
$newsolution ="CcsArchitecture"
$templatedir = "..\_CcsTemplate"
.\lib\solutionfactory\SolutionFactory-console.exe export $source_dir$projectName.sln $templatedir
delete_directory "$templatedir\template\build"
delete_directory "$templatedir\template\src\_ReSharper.CodeCampServer"
delete_file "$templatedir\template\latestversion\safesolutionnamepackage.exe"
delete_file "$templatedir\template\readme.txt"
copy_files ".\lib\solutionfactory\" "$templatedir\"
write "Creating $package_dir"
create_directory $package_dir
zip_directory $templatedir\template\ $package_dir\VisualStudioTemplate.exe
}
task Database {
exec { .\lib\tarantino\DatabaseDeployer.exe Rebuild $databaseServer $databaseName $databaseScripts}
}
task CommonAssemblyInfo {
$version = "1.0.$buildNumber.0"
create-commonAssemblyInfo "$version" $projectName "$source_dir\CommonAssemblyInfo.cs"
}
task Test {
copy_all_assemblies_for_test $test_dir
run_nunit "$projectName.UnitTests.dll"
run_nunit "$projectName.IntegrationTests.dll"
load_test_data "$projectName.IntegrationTests.dll"
}
task Compile -depends Clean {
exec { msbuild /t:build $source_dir$projectName.sln }
}
task Clean {
delete_file $package_file
delete_directory $build_dir
create_directory $test_dir
create_directory $result_dir
exec { msbuild /t:clean $source_dir\$projectName.sln }
}
task TestWithCoverage {
copy_all_assemblies_for_test $test_dir
run_nunit_with_coverage "$projectName.UnitTests.dll"
run_nunit_with_coverage "$projectName.IntegrationTests.dll"
}
task Inspection {
run_fxcop
run_source_monitor
}
task Package {
delete_directory $package_dir
copy_website_files "$source_dir\UI" "$package_dir\website"
copy_files "$source_dir\Database" "$package_dir\Database"
copy_files "$base_dir\lib\tarantino" "$source_dir\Database\Tools" @("*.pdb")
copy_all_assemblies_for_test "$package_dir\Tests"
copy_files "$base_dir\lib\cassini" "$package_dir\tests\tools\cassini"
copy_files "$base_dir\lib\nunit" "$package_dir\tests\tools\nunit"
copy_files "$base_dir\lib\gallio" "$package_dir\tests\tools\gallio"
copy_files "$base_dir\lib\nant" "$package_dir\nant" @( '*.pdb','*.xml')
copy_files "$base_dir\deployment" "$package_dir"
$agents_dir = "$package_dir\agents"
copy_files "$base_dir\lib\tinoBatchJobs" $agents_dir
copy_files "$source_dir\Ui\bin" $agents_dir
Copy_and_flatten $source_dir *.config $agents_dir
zip_directory $package_dir $package_file
}
# -------------------------------------------------------------------------------------------------------------
# generalized functions
# --------------------------------------------------------------------------------------------------------------
function global:zip_directory($directory,$file)
{
delete_file $file
cd $directory
&"$base_dir\lib\7zip\7za.exe" a -mx=9 -r -sfx $file *.*
cd $base_dir
}
function global:delete_file($file)
{
if($file) {
remove-item $file -force -ErrorAction SilentlyContinue | out-null}
}
function global:run_fxcop
{
& .\lib\FxCop\FxCopCmd.exe /out:$result_dir"FxCopy.xml" /file:$test_dir$projectname".*.dll" /quiet /d:$test_dir /c /summary | out-file $result_dir"fxcop.log"
}
function global:run_source_monitor
{
$command = $result_dir + "command.xml"
"<?xml version=""1.0"" encoding=""UTF-8"" ?>
<sourcemonitor_commands>
<write_log>true</write_log>
<command>
<project_file>build\results\sm_project.smp</project_file>
<project_language>CSharp</project_language>
<source_directory>src</source_directory>
<include_subdirectories>true</include_subdirectories>
<checkpoint_name>0</checkpoint_name>
<export>
<export_file>build\results\sm_summary.xml</export_file>
<export_type>1</export_type>
</export>
</command>
<command>
<project_file>build\results\sm_project.smp</project_file>
<checkpoint_name>0</checkpoint_name>
<export>
<export_file>build\results\sm_details.xml</export_file>
<export_type>2</export_type>
</export>
</command>
</sourcemonitor_commands>" | out-file $command -encoding "ASCII"
.\lib\sourcemonitor\sourcemonitor.exe /C $command | out-null
Convert-WithXslt -originalXmlFilePath $result_dir"sm_details.xml" -xslFilePath "lib\sourcemonitor\SourceMonitorSummaryGeneration.xsl" -outputFilePath $result_dir"sm_top15.xml"
}
function global:delete_directory($directory_name)
{
rd $directory_name -recurse -force -ErrorAction SilentlyContinue | out-null
}
function global:create_directory($directory_name)
{
mkdir $directory_name -ErrorAction SilentlyContinue | out-null
}
function global:run_nunit ($test_assembly)
{
exec { & lib\nunit\nunit-console-x86.exe $test_dir$test_assembly /nologo /nodots /xml=$result_dir$test_assembly.xml /exclude=DataLoader}
}
function global:load_test_data ($test_assembly)
{
exec { & lib\nunit\nunit-console-x86.exe $test_dir$test_assembly /nologo /nodots /include=DataLoader}
}
function global:run_nunit_with_coverage($test_assembly)
{
exec { .\lib\ncover\NCover.Console.exe $base_dir\lib\nunit\nunit-console.exe $test_dir$test_assembly /noshadow /nologo /nodots /xml=$result_dir$test_assembly.xml //x $result_dir"$test_assembly.Coverage.xml" //ias $projectName".Core;"$projectName".UI;"$projectName".Infrastructure;"$projectName".DependencyInjection" //w $test_dir //h $result_dir //reg}
}
function global:Copy_and_flatten ($source,$filter,$dest)
{
ls $source -filter $filter -r | cp -dest $dest
}
function global:copy_all_assemblies_for_test($destination){
create_directory $destination
Copy_and_flatten $source_dir *.dll $destination
Copy_and_flatten $source_dir *.config $destination
Copy_and_flatten $source_dir *.xml $destination
Copy_and_flatten $source_dir *.pdb $destination
}
function global:copy_website_files($source,$destination){
$exclude = @('*.user','*.dtd','*.tt','*.cs','*.csproj')
copy_files $source $destination $exclude
}
function global:copy_files($source,$destination,$exclude=@()){
create_directory $destination
Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}
}
function global:Convert-WithXslt($originalXmlFilePath, $xslFilePath, $outputFilePath)
{
## Simplistic error handling
$xslFilePath = resolve-path $xslFilePath
if( -not (test-path $xslFilePath) ) { throw "Can't find the XSL file" }
$originalXmlFilePath = resolve-path $originalXmlFilePath
if( -not (test-path $originalXmlFilePath) ) { throw "Can't find the XML file" }
#$outputFilePath = resolve-path $outputFilePath -ErrorAction SilentlyContinue
if( -not (test-path (split-path $originalXmlFilePath)) ) { throw "Can't find the output folder" }
## Get an XSL Transform object (try for the new .Net 3.5 version first)
$EAP = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
$script:xslt = new-object system.xml.xsl.xslcompiledtransform
trap [System.Management.Automation.PSArgumentException]
{ # no 3.5, use the slower 2.0 one
$ErrorActionPreference = $EAP
$script:xslt = new-object system.xml.xsl.xsltransform
}
$ErrorActionPreference = $EAP
## load xslt file
$xslt.load( $xslFilePath )
## transform
$xslt.Transform( $originalXmlFilePath, $outputFilePath )
}
function global:create-commonAssemblyInfo($version,$applicationName,$filename)
{
"using System;
using System.Reflection;
using System.Runtime.InteropServices;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: ComVisibleAttribute(false)]
[assembly: AssemblyVersionAttribute(""$version"")]
[assembly: AssemblyFileVersionAttribute(""$version"")]
[assembly: AssemblyCopyrightAttribute(""Copyright 2010"")]
[assembly: AssemblyProductAttribute(""$applicationName"")]
[assembly: AssemblyCompanyAttribute("""")]
[assembly: AssemblyConfigurationAttribute(""release"")]
[assembly: AssemblyInformationalVersionAttribute(""$version"")]" | out-file $filename -encoding "ASCII"
}