-
Notifications
You must be signed in to change notification settings - Fork 2
/
BuildTargets.xml
214 lines (176 loc) · 9.4 KB
/
BuildTargets.xml
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
<?xml version="1.0" encoding="utf-8" ?>
<project name="BuildTargets">
<!-- Set appropriate variables depending if this is a local or CCNet build -->
<target name="DetermineBuild" description="">
<property name="solution.buildspace" value="${path::combine(local.buildspace, solution.name)}" />
<property name="buildspace.src.dir" value="${path::combine(solution.buildspace, solution.src.dir)}" />
<property name="solution.workspace" value="${path::combine(local.workspace, solution.name)}" />
<property name="is.release.local" value="true"/>
<property name="azure.buildspace" value="${path::combine(buildspace.src.dir, azure.project.name)}" />
<if test="${property::exists('CCNetLabel')}">
<property name="is.release.local" value="false"/>
<property name="version.tag" value="${CCNetLabel}"/>
</if>
<echo message="is.release.local = ${is.release.local}"/>
<echo message="Version.tag = ${version.tag}"/>
<echo message="solution.workspace = ${solution.workspace}" />
<echo message="solution.buildspace = ${solution.buildspace}" />
<echo message="buildspace.src.dir = ${buildspace.src.dir}" />
<echo message="azure.buildspace = ${buildspace.src.dir}" />
</target>
<!-- Ensure clean project assembly workspace directory for local builds -->
<target name="CleanLocalBuildspace">
<echo message="Deleting dir ${solution.buildspace}"/>
<delete dir="${solution.buildspace}"/>
<mkdir dir="${solution.buildspace}" />
</target>
<!-- Copy files to build space -->
<target name="AssembleFromWorkspace" depends="CleanLocalBuildspace">
<echo message="Assemble from workspace ${solution.workspace} to ${solution.buildspace}"/>
<copy todir="${solution.buildspace}" includeemptydirs="false">
<fileset basedir="${solution.workspace}">
<include name="**/*" />
<exclude name="**/packages/**" />
<exclude name="**/bin/**"/>
<exclude name="**/obj/**"/>
<exclude name="*/Release/**" />
<exclude name="*/Debug/**" />
<exclude name="**/.git/**" />
<exclude name="TestResults/**"/>
<exclude name="**/*.user" />
</fileset>
</copy>
</target>
<!-- Update each project's assemblyinfo.cs file with version number and company info etc -->
<target name="UpdateAssemblyInfo">
<foreach item="String" in="${solution.projects}" delim="," property="assembly.project.name">
<property name="src.dir" value="${path::combine(buildspace.src.dir, assembly.project.name)}" />
<property name="assemblyinfo.cs" value="${path::combine(src.dir, 'Properties\AssemblyInfo.cs')}" />
<call target="CreateAssemblyInfo"/>
</foreach>
</target>
<!-- Create new AssemblyInfo file with version number and company info-->
<target name="CreateAssemblyInfo">
<echo message="Creating assembly file: ${assemblyinfo.cs}" />
<asminfo output="${assemblyinfo.cs}" language="CSharp">
<imports>
<import namespace="System.Reflection" />
<import namespace="System.Runtime.CompilerServices" />
<import namespace="System.Runtime.InteropServices" />
</imports>
<attributes>
<attribute type="AssemblyTitleAttribute" value="${assembly.project.name}" />
<attribute type="AssemblyDescriptionAttribute" value="" />
<attribute type="AssemblyConfigurationAttribute" value="" />
<attribute type="AssemblyCompanyAttribute" value="${company.name}" />
<attribute type="AssemblyProductAttribute" value="${assembly.project.name}" />
<attribute type="AssemblyCopyrightAttribute" value="Copyright (c) ${company.name} ${datetime::get-year(datetime::now())}" />
<attribute type="AssemblyTrademarkAttribute" value="" />
<attribute type="AssemblyCultureAttribute" value="" />
<attribute type="ComVisibleAttribute" value="false" />
<attribute type="AssemblyVersionAttribute" value="${version.tag}" />
<attribute type="AssemblyFileVersionAttribute" value="${version.tag}" />
</attributes>
</asminfo>
</target>
<target name="CompileSolution" description="Compiles and packages the solution ready for MsDeploy">
<echo message="Compiling soultion: ${solution.buildspace}\${solution.name} with configuration: ${release.configuration}"/>
<exec program="${msbuild4.exe}">
<arg value="${solution.buildspace}\${solution.name}.sln" />
<arg value="/p:Configuration=${release.configuration}" />
<arg value="/p:DeployOnBuild=true"/>
<arg value="/p:DeployTarget=Package"/>
<arg value="/p:AutoParameterizationWebConfigConnectionStrings=false" if="${create.azure.package}" />
<!--This flag must be set to false on azure builds-->
<arg value="/p:WarningLevel=4" />
<arg value="/p:TreatWarningsAsErrors=true"/>
<arg value="/v:m" />
</exec>
</target>
<target name="RunNunitTests">
<foreach item="String" in="${test.project.names}" delim="," property="test.project.name">
<echo message="Running Nunit tests for ${test.project.name}"/>
<exec program="${nunit-console.exe}">
<arg value="${buildspace.src.dir}/${test.project.name}/bin/${release.configuration}/${test.project.name}.dll" />
<arg value="/xml=${buildspace.src.dir}/${test.project.name}/bin/${release.configuration}/${test.project.name}-results.xml" />
</exec>
</foreach>
</target>
<target name="RunDbMigrations" description="Migrate the database to the latest version">
<migrate
database="${database.type}"
connection="${connection.string}"
target="${buildspace.src.dir}/${migrations.project.name}/bin/${release.configuration}/${migrations.project.name}.dll"
/>
</target>
<target name="RollbackDbMigrations" description="Migrates the database back to specified version">
<migrate
database="${database.type}"
connection="${connection.string}"
target="${buildspace.src.dir}/${migrations.project.name}/bin/${release.configuration}/${migrations.project.name}.dll"
task="migrate:down"
to="${rollback.to.version}"
/>
</target>
<target name="CreateAzurePackage" description="Creates package for uploading to Azure">
<property name="package.dir" value ="${buildspace.src.dir}/${azure.role.project.name}/obj/${release.configuration}/Package/PackageTmp/"/>
<echo message="Executing cspack for ${solution.name}, with following arguments:"/>
<echo message="/role: ${azure.role.project.name};${package.dir} "/>
<echo message="/rolePropertiesFile:${azure.role.project.name};.\AzureRoleProperties.txt" />
<echo message="/sitePhysicalDirectories:${azure.role.project.name};Web;${package.dir}"/>
<echo message="/out:${azure.buildspace}/${solution.name}-${release.configuration}-${version.tag}.cspkg"/>
<echo></echo>
<!--Create AzureRoleProperties file-->
<touch file="AzureRoleProperties.txt" />
<echo file="AzureRoleProperties.txt" message="TargetFrameWorkVersion=v4.0 
" />
<echo file="AzureRoleProperties.txt" append="true" message="EntryPoint=${azure.role.project.name}.dll" />
<exec program="${cspack.exe}">
<arg value="${azure.buildspace}/ServiceDefinition.csdef" />
<arg value="/role:${azure.role.project.name};${package.dir}"/>
<arg value="/rolePropertiesFile:${azure.role.project.name};.\AzureRoleProperties.txt"/>
<arg value="/sitePhysicalDirectories:${azure.role.project.name};Web;${package.dir}"/>
<arg value="/out:${azure.buildspace}/${solution.name}-${release.configuration}-${version.tag}.cspkg"/>
</exec>
<!--TODO add release configs-->
<echo message="Copy Azure package from ${azure.buildspace} to ${local.releasespace}/${solution.name}"/>
<copy todir="${local.releasespace}/${solution.name}" verbose="true" includeemptydirs="false">
<fileset basedir="${azure.buildspace}">
<include name="**/*.cspkg" />
<include name="**/${azure.service.config.file}" />
<exclude name="**/*.csdef"/>
<exclude name="**/bin/**"/>
</fileset>
</copy>
</target>
<target name="ParseSubscriptionDetails">
<xmlpeek file="${azure.subscription.credentials.file}"
property="azure.subscription.id"
xpath="//x:Subscriptions/x:Subscription/x:SubscriptionId">
<namespaces>
<namespace prefix="x" uri="urn:Microsoft.WindowsAzure.Management:WaPSCmdlets" />
</namespaces>
</xmlpeek>
<xmlpeek file="${azure.subscription.credentials.file}"
property="azure.thumbprint"
xpath="//x:Subscriptions/x:Subscription/x:Thumbprint">
<namespaces>
<namespace prefix="x" uri="urn:Microsoft.WindowsAzure.Management:WaPSCmdlets" />
</namespaces>
</xmlpeek>
</target>
<target name="DeployAzurePackage" depends="ParseSubscriptionDetails" description="Deploys your Azure package to the Cloud :-)">
<property name="deploy.label" value="${solution.name}-${release.configuration}-${version.tag}" />
<exec program="${powershell.exe} ">
<arg value=".\DeployAzureApp.ps1" />
<arg value="-ExecutionPolicy unrestricted" />
<arg value="-environment ${azure.deployment.environment}" />
<arg value="-serviceName ${azure.hosted.service.name}"/>
<arg value="-thumbprint ${azure.thumbprint}"/>
<arg value="-subscriptionId '${azure.subscription.id}'"/>
<arg value="-storageAccountName ${azure.storage.account.name}"/>
<arg value="-packageLocation ${local.releasespace}\${solution.name}\${solution.name}-${release.configuration}-${version.tag}.cspkg" />
<arg value="-cloudConfigLocation ${local.releasespace}\${solution.name}\${azure.service.config.file}" />
<arg value="-deploymentLabel ${deploy.label}" />
</exec>
</target>
</project>