forked from Azure/autorest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.proj
352 lines (273 loc) · 16.9 KB
/
build.proj
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Targets:
/t:Clean
Removes temporary build outputs.
/t:Build
Builds assemblies.
/t:Test
Run unit tests.
/t:Publish
Publishes the built packages. You will need to include your
publishing key when running. Include: /p:NuGetKey=YOUR_PUBLISHING_KEY
/t:CodeAnalysis
Run Code analysis.
Properties of interest:
/p:Scope
'All' : builds ClientRuntime and CodeGenerator solutions
'CodeGenerator': builds CodeGenerator solution only
'ClientRuntime': builds ClientRuntime solution only
By default, it builds all.
/P:CodeSign=True
Code sign binaries, mainly for official release
/p:CodeSign=True;DelaySign=True
Test the code sign workflow locally
/p:NuGetKey=NUGET_PUBLISHING_KEY
Provides the key used to publish to a NuGet or MyGet server.
This key should never be committed to source control.
/p:PublishSymbolSourcePackages
A true/false value indicating whether to push the symbol + source
packages to a symbol server.
/p:NuGetPublishingSource=Uri
The NuGet Server to push packages to.
/p:NuGetSymbolPublishingSource=Uri
The NuGet Server to push symbol + source packages to.
/p:VersionSuffix=Nightly-20160102
Provide a version suffix for Nightly builds
-->
<PropertyGroup>
<LibraryRoot>$(MSBuildThisFileDirectory)</LibraryRoot>
<LibrarySourceFolder>$(LibraryRoot)</LibrarySourceFolder>
<LibraryToolsFolder>$(LibraryRoot)Tools</LibraryToolsFolder>
<BinariesFolder>$(LibraryRoot)binaries</BinariesFolder>
<TestResultsFolder>$(LibraryRoot)TestResults</TestResultsFolder>
<PackageOutputDir>$(BinariesFolder)\packages</PackageOutputDir>
<!-- Default to Debug -->
<Configuration Condition="'$(Configuration)' == '' ">Debug</Configuration>
<CodeSign Condition=" '$(CodeSign)' == '' ">false</CodeSign>
<!-- Only set set this to true for testing the code sign workflow locally. -->
<DelaySign Condition =" '$(DelaySign)' == '' ">false</DelaySign>
<Scope Condition=" '$(Scope)' == '' ">all</Scope>
<ZipExeFolder>$(LibraryToolsFolder)\7-Zip</ZipExeFolder>
<ZipExe>$(ZipExeFolder)\7z.exe</ZipExe>
<!-- Default Package Sources -->
<NugetSource Condition=" '$(NuGetPublishingSource)' != '' ">$(NuGetPublishingSource)</NugetSource>
<NugetSource Condition=" '$(NuGetPublishingSource)' == '' ">https://www.nuget.org/api/v2/package/</NugetSource>
<SymbolSource Condition=" '$(SymbolPublishingSource)' != '' ">$(SymbolPublishingSource)</SymbolSource>
<SymbolSource Condition=" '$(SymbolPublishingSource)' == '' ">https://nuget.smbsrc.net/</SymbolSource>
<!-- This property is used by the continuous intergration job.
Do not remove without first updating the CI job. Also due to a known limitation,
make sure pathes do not end with a backslash -->
<CorporateScanPaths>$(LibrarySourceFolder)src</CorporateScanPaths>
<BinscopeScanPath>$(BinariesFolder)</BinscopeScanPath>
<!-- Public token of MSSharedLibKey.snk. -->
<StrongNameToken Condition=" '$(StrongNameToken)' == '' ">31bf3856ad364e35</StrongNameToken>
<!-- CI build related. -->
<ContinueOnPoliCheckError>true</ContinueOnPoliCheckError>
<!--OnPremiseBuildTasks is not a good name, but CI server is using that, will update across soon-->
<CIToolsPath>$(OnPremiseBuildTasks)</CIToolsPath>
<OnPremiseBuild Condition=" Exists('$(OnPremiseBuildTasks)') ">true</OnPremiseBuild>
<OnPremiseBuild Condition=" ! Exists('$(OnPremiseBuildTasks)') ">false</OnPremiseBuild>
<CanPublish Condition="'$(Scope)' == 'CodeGenerator'">true</CanPublish>
<CanPublish Condition="'$(Scope)' == 'ClientRuntime'">true</CanPublish>
<CanPublish Condition="'$(CanPublish)' == ''">false</CanPublish>
<!-- NuGet command line -->
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(LibraryToolsFolder)\nuget.exe"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT'">mono "$(LibraryToolsFolder)\NuGet.exe"</NuGetCommand>
<!-- Release build: when no VersionSuffix is passed, and CodeSign is true -->
<VersionSuffix Condition="$(VersionSuffix) == '' AND '$(CodeSign)' == 'true' "></VersionSuffix>
<!-- Nightly builds have their own VersionSuffix ( ie, -Nightly20160607 )-->
<VersionSuffix Condition=" $(NightlyBuild) == 'true' ">Nightly$([System.DateTime]::Now.ToString("yyyyMMdd"))</VersionSuffix>
<!-- Otherwise, default Version Suffix if not codesigning-->
<VersionSuffix Condition="$(VersionSuffix) == '' AND '$(CodeSign)' != 'true'">preview-0.17</VersionSuffix>
</PropertyGroup>
<!-- ClientRuntime projects that can be built into packages -->
<ItemGroup Condition="'$(Scope)' == 'ClientRuntime' OR '$(Scope)' == 'all'">
<PackageableLibraries Include="src/client/*/project.json" Exclude="src/client/*.Tests/project.json;src/client/*.Etw/project.json" Condition=" '$(OS)' == 'Windows_NT'"/>
<PackageableLibraries Include="src/client/*/project.json" Exclude="src/client/*.Tests/project.json;src/client/*.Etw/project.json;src/client/*.Log4Net/project.json" Condition=" '$(OS)' != 'Windows_NT'"/>
</ItemGroup>
<!-- CodeGenerator projects that can be built into packages -->
<ItemGroup Condition="'$(Scope)' == 'CodeGenerator' OR '$(Scope)' == 'all'">
<PackageableLibraries Include="$(LibraryRoot)/src/core/AutoRest/project.json" />
</ItemGroup>
<!-- .xproj files (used for clean and razor compile tasks -->
<ItemGroup>
<XProjFiles Include="src/**/*.xproj" />
</ItemGroup>
<!-- Our Custom Tasks -->
<Import Project="tools\Autorest.Build.Tasks"/>
<!-- Custom Tasks from OnPremiseBuild system -->
<UsingTask Condition=" $(OnPremiseBuild) " TaskName="CodeSigningTask" AssemblyFile="$(CIToolsPath)\Microsoft.WindowsAzure.Tools.Build.Tasks.OnPremise.dll" />
<UsingTask Condition=" $(OnPremiseBuild) " TaskName="CorporateValidation" AssemblyFile="$(CIToolsPath)\Microsoft.WindowsAzure.Tools.Build.Tasks.OnPremise.dll" />
<Import Condition=" $(OnPremiseBuild) == 'true' " Project="$(CIToolsPath)\Microsoft.WindowsAzure.Build.OnPremise.msbuild" />
<!-- Packaging is the same as building at this point -->
<Target Name="Package" DependsOnTargets="Clean;Build" Condition="'$(Configuration)' == 'Release'" />
<!-- Publishing uploads the packages to the nuget server -->
<Target Name="Publish" DependsOnTargets="Package" Condition="'$(Configuration)' == 'Release'" >
<Error Condition=" $(CanPublish) == false " Text="Do not attempt to publish both the ClientRuntime and the CodeGenerator at the same time. You must specify /p:Scope=CodeGenerator or /p:Scope=ClientRuntime" />
<Error Condition=" '$(NuGetKey)' == '' " Text="You must provide the NuGetKey parameter to the build: /p:NuGetKey=YOUR_PUBLISHING_KEY" />
<ItemGroup Condition="'$(Scope)' == 'CodeGenerator'">
<NugetPackagesToPublish Include="$(PackageOutputDir)\*.nupkg" Exclude="src\core\AutoRest\**\*.symbols.nupkg"/>
<SymbolPackagesToPublish Include="src\core\AutoRest\**\*.symbols.nupkg"/>
</ItemGroup>
<ItemGroup Condition="'$(Scope)' == 'ClientRuntime'">
<NugetPackagesToPublish Include="$(PackageOutputDir)\*.nupkg" Exclude="src\client\**\*.symbols.nupkg"/>
<SymbolPackagesToPublish Include="src\client\**\*.symbols.nupkg"/>
</ItemGroup>
<Message Importance="high" Text="Publishing main package to the cloud at $(NugetSource)" />
<Exec Command="$(NuGetCommand) push "%(NugetPackagesToPublish.FullPath)" $(NuGetKey) -Source $(NugetSource)" IgnoreExitCode="false" />
<Message Importance="high" Text="Publishing symbols package to the cloud at $(SymbolSource)" />
<Exec Command="$(NuGetCommand) push "%(SymbolPackagesToPublish.FullPath)" $(NuGetKey) -Source $(SymbolSource)" IgnoreExitCode="true" />
</Target>
<Target Name="Build" DependsOnTargets="RestoreNugetPackages;RazorCompile;">
<!-- conditial tasks -->
<CallTarget Targets="BuildServerPreparation" Condition=" '$(CodeSign)' == 'true' " />
<CallTarget Targets="DisableSN" Condition=" '$(OS)' == 'Windows_NT'"/>
<!-- use dotnet pack to build those that are supposed to be packaged -->
<Exec Command="dotnet pack --configuration $(Configuration) --version-suffix $(VersionSuffix)" WorkingDirectory="%(PackageableLibraries.RootDir)%(PackageableLibraries.Directory)" Condition="$(VersionSuffix) != ''"/>
<Exec Command="dotnet pack --configuration $(Configuration) " WorkingDirectory="%(PackageableLibraries.RootDir)%(PackageableLibraries.Directory)" Condition="$(VersionSuffix) == ''"/>
<CallTarget Targets="CodeSignBinaries" Condition=" '$(CodeSign)' == 'true' " />
</Target>
<Target Name="DisableSN" >
<!-- Check for admin privs -->
<Exec Command="net session" IgnoreExitCode="true" StandardErrorImportance="Low">
<Output PropertyName="isadmin" TaskParameter="ExitCode" />
</Exec>
<!-- Disable strong name checking -->
<Exec Command='"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" -Vr *' Condition="$(isadmin) == 0"/>
<Exec Command='"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\sn.exe" -Vr *' Condition="$(isadmin) == 0"/>
</Target>
<Target Name="EnableSN" >
<!-- Check for admin privs -->
<Exec Command="net session" IgnoreExitCode="true" StandardErrorImportance="Low">
<Output PropertyName="isadmin" TaskParameter="ExitCode" />
</Exec>
<!-- Enable strong name checking -->
<Exec Command='"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe" -Vx *' Condition="$(isadmin) == 0"/>
<Exec Command='"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\sn.exe" -Vx *' Condition="$(isadmin) == 0"/>
</Target>
<!-- clean out compiled files -->
<Target Name="Clean">
<Message Text="Individually: %(XProjFiles.Identity)" Importance="High" />
<Message Text="All: @(XProjFiles)" Importance="High" />
<MSBuild Projects="%(XProjFiles.Identity)"
Properties="Configuration=$(Configuration);Platform=Any CPU"
Targets="Clean"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'CodeGenerator'" />
<RemoveDir Directories="$(BinariesFolder)" />
<RemoveDir Directories="$(TestResultsFolder)" />
<MakeDir Directories="$(BinariesFolder)" />
<MakeDir Directories="$(TestResultsFolder)" />
</Target>
<Target Name="CodeAnalysis" >
<!-- NetCore project currently do not have support for code analysis (Roslyn can do alot of that anyway.) -->
</Target>
<!-- Run tests. -->
<Target Name="Test" DependsOnTargets="RestoreNugetPackages">
<Exec Command="gulp test"/>
</Target>
<!--
== Sign Packaged Binaries ==
Note: This pulls the assemblies out of the created packages and feeds them thru the OnPremiseBuild tools for code signing.
-->
<Target Name="CodeSignBinaries" Condition="'$(Configuration)' == 'Release'" DependsOnTargets="GetZip">
<Error Condition=" !$(OnPremiseBuild) and !$(DelaySign) " Text="No CI tools path available, the code sign will be unable to continue. $(CIToolsPath)" />
<Message Text="Code signing" Importance="high" />
<ItemGroup Condition="'$(Scope)' == 'CodeGenerator'">
<PackagesToSign Include="src\core\AutoRest\**\*.nupkg" Exclude="src\core\AutoRest\**\*.symbols.nupkg"/>
</ItemGroup>
<ItemGroup Condition="'$(Scope)' == 'ClientRuntime'">
<PackagesToSign Include="src\client\**\*.nupkg" Exclude="src\client\**\*.symbols.nupkg"/>
</ItemGroup>
<PropertyGroup>
<_UnsignedFolder>$(PackageOutputDir)\unsigned</_UnsignedFolder>
<_SignedFolder>$(PackageOutputDir)\signed</_SignedFolder>
</PropertyGroup>
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="SdkPath"/>
</GetFrameworkSdkPath>
<Message Text="%(PackagesToSign.Identity)" Importance="low" />
<RemoveDir Directories="$(_UnsignedFolder);$(_SignedFolder)" ContinueOnError="false" />
<RemoveDir Directories="@(PackagesToSign->'$(PackageOutputDir)\%(Filename)')" ContinueOnError="false" />
<MakeDir Directories="$(_UnsignedFolder);$(_SignedFolder)" />
<Exec Command="$(ZipExe) x -y -scsUTF-8 -o@(PackagesToSign->'$(PackageOutputDir)\%(Filename)') %(PackagesToSign.Identity)" />
<!-- clean out OPC files from signing directory -->
<RemoveDir Directories="@(PackagesToSign->'%(RootDir)%(Directory)\%(Filename)\_rels')" />
<Delete Files="@(PackagesToSign->'%(RootDir)%(Directory)\%(Filename)\[Content_Types].xml')" />
<ItemGroup>
<_TempBinaries Include="$(PackageOutputDir)\**\*.dll" Exclude="$(PackageOutputDir)\**\Newtonsoft.Json.dll;$(PackageOutputDir)\**\YamlDotNet.dll" />
<_TempBinaries Include="$(PackageOutputDir)\**\*.exe" />
<_PackageBinaries Include="@(_TempBinaries)">
<!-- Flattened file for signing -->
<UnsignedFlatFileName>$(_UnsignedFolder)\$([System.String]::new('%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '__'))</UnsignedFlatFileName>
<SignedFlatFileName>$(_SignedFolder)\$([System.String]::new('%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '__'))</SignedFlatFileName>
</_PackageBinaries>
</ItemGroup>
<Copy SourceFiles="@(_PackageBinaries)" DestinationFiles="@(_PackageBinaries->'%(UnsignedFlatFileName)')"></Copy>
<ValidateStrongNameSignatureTask
SdkPath="$(SdkPath)"
Assembly="%(_PackageBinaries.UnsignedFlatFileName)"
ExpectedTokenSignature="$(StrongNameToken)"
ExpectedDelaySigned="true"
ContinueOnError="false"/>
<CodeSigningTask
Description="Microsoft Azure SDK"
Keywords="Microsoft Azure .NET SDK"
UnsignedFiles="@(_PackageBinaries->'%(UnsignedFlatFileName)')"
DestinationPath="$(_SignedFolder)"
SigningLogPath="$(PackageOutputDir)\signing.log"
ToolsPath="$(CIToolsPath)"
Condition="!$(DelaySign)"/>
<!--If we are testing locally then we copy the binaries and do not submit to the code sign server-->
<!-- <Copy SourceFiles="@(_PackageBinaries->'%(UnsignedFlatFileName)')" DestinationFolder="$(_SignedFolder)" Condition="$(DelaySign)" /> -->
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath"/>
</GetFrameworkSdkPath>
<ValidateStrongNameSignatureTask
SdkPath="$(SdkPath)"
Assembly="%(_PackageBinaries.SignedFlatFileName)"
ExpectedTokenSignature="$(StrongNameToken)"
ExpectedDelaySigned="false"
ContinueOnError="false"
Condition="!$(DelaySign)"/>
<!-- copy the original nupkg file into the target location -->
<Copy SourceFiles="@(_PackageBinaries->'%(SignedFlatFileName)')" DestinationFiles="@(_PackageBinaries->'%(FullPath)')"></Copy>
<!-- zip files back up into package -->
<Exec Command="$(ZipExe) a -tzip -mx9 -r -y $(PackageOutputDir)\%(PackagesToSign.Filename).nupkg" WorkingDirectory="$(PackageOutputDir)\%(PackagesToSign.Filename)" />
<Delete Files="@(_PackageBinaries->'%(UnsignedFlatFileName)')" />
<Delete Files="@(_PackageBinaries->'%(SignedFlatFileName)')" />
<CallTarget Targets="ValidateCorporateCompliance" Condition="!$(DelaySign)"/>
</Target>
<Target Name="RestoreNugetPackages">
<Exec Command="dotnet restore $(MSBuildThisFileDirectory)" ContinueOnError="false"/>
<Exec Command="$(NuGetCommand) install xunit.runner.console -Version 2.1.0 -OutputDirectory $(LibraryRoot)packages" ContinueOnError="false"/>
</Target>
<Target Name="RazorCompile">
<MSBuild BuildInParallel="false" Projects="%(XProjFiles.Identity)"
Properties="Configuration=$(Configuration);Platform=Any CPU"
Targets="CompileRazorTemplates" />
</Target>
<!-- Official releases require tools only available on corp network. -->
<Target Name="ValidateCorporateCompliance">
<Error Text="This target must be run in an on-premise build server." Condition=" '$(OnPremiseBuild)'=='false' " />
<CallTarget Targets="CorporateValidation" />
<CallTarget Targets="RunBinscope" />
</Target>
<!-- Build server tasks. -->
<Target Name="BuildServerPreparation">
<!-- Log build server information. -->
<Message Text="Build Server Information" Importance="high" />
<Message Text="Hostname : $(COMPUTERNAME)" />
<Message Text="Build Account : $(USERDOMAIN)\$(USERNAME)" />
<!-- Log build properties. -->
<Message Text="Build Properties and Variables" Importance="high" />
<Message Text="Source folder : $(LibrarySourceFolder)" />
</Target>
<Target Name="GetZip">
<Message Text="Ensure 7zip is available" />
<Exec
Command="$(LibraryToolsFolder)\AzCopy\AzCopy.exe /Source:https://azuresdktools.blob.core.windows.net/7-zip /S /Dest:$(ZipExeFolder) /Y"
Condition="!Exists('$(ZipExe)')" />
</Target>
</Project>