forked from Azure/autorest
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.proj
349 lines (300 loc) · 16.6 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
<?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:Package
Builds NuGet packages using the binaries folder contents.
The packages will drop to .\binaries\packages.
/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.
-->
<PropertyGroup>
<ClientRuntimeSolution>ClientRuntime.sln</ClientRuntimeSolution>
<ClientRuntimeWindowsSolution>ClientRuntimeWindows.sln</ClientRuntimeWindowsSolution>
<CodeGeneratorSolution>CodeGenerator.sln</CodeGeneratorSolution>
<LibraryRoot>$(MSBuildThisFileDirectory)</LibraryRoot>
<LibrarySourceFolder>$(LibraryRoot)</LibrarySourceFolder>
<LibraryToolsFolder>$(LibraryRoot)Tools</LibraryToolsFolder>
<BinariesFolder>$(LibraryRoot)binaries</BinariesFolder>
<TestResultsFolder>$(LibraryRoot)TestResults</TestResultsFolder>
<PackageOutputDir>$(BinariesFolder)\packages</PackageOutputDir>
<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>
<DnxVersion>1.0.0-rc1-final</DnxVersion>
</PropertyGroup>
<ItemGroup>
<LibraryFxTargetList Condition=" '$(FxTargetList)' == '' and '$(Scope)' == 'CodeGenerator' " Include="net45" />
<LibraryFxTargetList Condition=" '$(FxTargetList)' != '' " Include="$(FxTargetList)" />
</ItemGroup>
<PropertyGroup>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(LibraryToolsFolder)\nuget.exe"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT'">mono "$(LibraryToolsFolder)\NuGet.exe"</NuGetCommand>
</PropertyGroup>
<UsingTask AssemblyFile="Tools\AutoRest.Build.Tasks.dll" TaskName="ValidateStrongNameSignatureTask" />
<UsingTask AssemblyFile="Tools\AutoRest.Build.Tasks.dll" TaskName="RegexReplaceTask" />
<UsingTask AssemblyFile="Tools\AutoRest.Build.Tasks.dll" TaskName="SetEnvVar" />
<!-- CI build related. -->
<PropertyGroup>
<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>
</PropertyGroup>
<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" />
<ItemGroup>
<DnxLibraries Include="$(LibraryRoot)/ClientRuntimes/CSharp/*/project.json" />
<DnxLibraries Include="$(LibraryRoot)/AutoRest/Generators/CSharp/*/project.json" />
</ItemGroup>
<Target Name="Build" DependsOnTargets="RestoreNugetPackages">
<CallTarget Targets="BuildMsBuildTask" />
<CallTarget Targets="BuildServerPreparation" Condition=" '$(CodeSign)' == 'true' " />
<CallTarget Targets="BuildDnxLibraries" Condition=" '$(OS)' == 'Windows_NT' "/>
<!--
The solution file contains configurations for each platform such as Portable-Debug, Net45-Release, etc
When invoking msbuild, provide the right configuration name.
-->
<MSBuild Projects="$(CodeGeneratorSolution)"
Properties="Configuration=Net45-$(Configuration);Platform=Any CPU;CodeSign=$(CodeSign)"
Targets="Build"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'CodeGenerator'" />
<ItemGroup>
<_OriginalDnxPackages Include="$(LibraryRoot)/ClientRuntimes/CSharp/**/bin/$(Configuration)/*.nupkg" />
</ItemGroup>
<Copy SourceFiles="@(_OriginalDnxPackages)" DestinationFolder="$(LibraryRoot)\dnx"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'ClientRuntime'"/>
<Copy SourceFiles="@(_OriginalDnxPackages)" DestinationFolder="$(PackageOutputDir)"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'ClientRuntime'"/>
<CallTarget Targets="CodeSignBinaries" Condition=" '$(CodeSign)' == 'true' " />
</Target>
<Target Name="BuildDnxLibraries" DependsOnTargets="RestoreNugetPackages">
<Exec Command="dnu build --configuration $(Configuration)" WorkingDirectory="%(DnxLibraries.RootDir)%(DnxLibraries.Directory)"/>
<Exec Command="dnu pack --configuration $(Configuration)" WorkingDirectory="%(DnxLibraries.RootDir)%(DnxLibraries.Directory)"/>
<ItemGroup>
<_OriginalDnxPackages Include="%(DnxLibraries.RootDir)%(DnxLibraries.Directory)\bin\*\*.nupkg" />
</ItemGroup>
<Copy SourceFiles="@(_OriginalDnxPackages)" DestinationFolder="$(LibraryRoot)\dnx" />
</Target>
<!-- Project files import some targets coming from nuget packages, so need to restore them first to avoid errors
such as "The imported project ....build\Microsoft.Bcl.Build.targets was not found. " -->
<Target Name="Clean">
<MSBuild Projects="$(CodeGeneratorSolution)"
Properties="Configuration=Net45-$(Configuration);Platform=Any CPU"
Targets="Clean"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'CodeGenerator'" />
<RemoveDir Directories="$(BinariesFolder)" />
<RemoveDir Directories="$(TestResultsFolder)" />
</Target>
<Target Name="CodeAnalysis" DependsOnTargets="RestoreNugetPackages">
<!--Note, we use "Rebuild" rather "Build", because code analysis happens during the build, and this ensures the build is not skipped-->
<!-- DNX project currently do not have support for code analysis -->
<!--<MSBuild Projects="$(ClientRuntimeSolution)"
Properties="Configuration=%(LibraryFxTargetList.Identity)-$(Configuration);Platform=Any CPU;RunCodeAnalysis=true;CodeAnalysisTreatWarningsAsErrors=true"
Targets="Rebuild"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'ClientRuntime'" />-->
<MSBuild Projects="$(CodeGeneratorSolution)"
Properties="Configuration=Net45-$(Configuration);Platform=Any CPU;RunCodeAnalysis=true;CodeAnalysisTreatWarningsAsErrors=true"
Targets="Rebuild"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'CodeGenerator'" />
</Target>
<!-- Run tests. -->
<Target Name="Test" DependsOnTargets="RestoreNugetPackages">
<Exec Command="gulp test"/>
</Target>
<PropertyGroup>
<!-- 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)ClientRuntimes;$(LibrarySourceFolder)AutoRest</CorporateScanPaths>
<BinscopeScanPath>$(BinariesFolder)</BinscopeScanPath>
<!-- Public token of MSSharedLibKey.snk. -->
<StrongNameToken Condition=" '$(StrongNameToken)' == '' ">31bf3856ad364e35</StrongNameToken>
</PropertyGroup>
<Target Name="SignBinariesForAFxTarget">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="SdkPath"/>
</GetFrameworkSdkPath>
<ItemGroup>
<DelaySignedAssembliesToValidate Include="binaries\net45\unsigned\*.*" />
</ItemGroup>
<ValidateStrongNameSignatureTask
SdkPath="$(SdkPath)"
Assembly="%(DelaySignedAssembliesToValidate.Identity)"
ExpectedTokenSignature="$(StrongNameToken)"
ExpectedDelaySigned="true"
ContinueOnError="false" />
<CodeSigningTask
Description="Microsoft AutoRest"
Keywords="Microsoft AutoRest"
UnsignedFiles="@(DelaySignedAssembliesToValidate)"
DestinationPath="binaries\net45"
SigningLogPath="binaries\net45\signing.log"
ToolsPath="$(CIToolsPath)"
Condition="!$(DelaySign)"/>
<!-- DelaySigned binaries copied locally for testing and not submitted to codesign service. -->
<Copy SourceFiles="@(DelaySignedAssembliesToValidate)" DestinationFolder="binaries\net45" Condition="$(DelaySign)" />
<ItemGroup>
<AfterSignedAssembliesToValidate Include="binaries\net45\*.dll;binaries\net45\*.exe"
Exclude="binaries\net45\Newtonsoft.*.dll" />
</ItemGroup>
<ValidateStrongNameSignatureTask
SdkPath="$(SdkPath)"
Assembly="%(AfterSignedAssembliesToValidate.Identity)"
ExpectedTokenSignature="$(StrongNameToken)"
ExpectedDelaySigned="false"
ContinueOnError="false"
Condition="!$(DelaySign)"/>
<RemoveDir Directories="binaries\net45\unsigned;" ContinueOnError="true" />
</Target>
<Target Name="CodeSignBinaries">
<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" />
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="SignBinariesForAFxTarget"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'CodeGenerator'"
Properties="StrongNameToken=$(StrongNameToken)">
</MSBuild>
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="SignAssembliesInDnxPackages"
Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'ClientRuntime'"
Properties="StrongNameToken=$(StrongNameToken)">
</MSBuild>
<CallTarget Targets="ValidateCorporateCompliance" Condition="!$(DelaySign)"/>
</Target>
<!--
The build tasks project is used for:
providing date-based build numbers,
processing regular expressions text replacements (e.g. in NuGet specs),
validating strong name signatures.
-->
<Target Name="BuildMsBuildTask" DependsOnTargets="RestoreNugetPackages">
<MSBuild Projects="$(LibraryToolsFolder)\AutoRest.Build.Tasks\AutoRest.Build.Tasks.csproj"
Targets="Build"
Properties="Configuration=Debug;Platform=AnyCPU"/>
</Target>
<Target Name="RestoreNugetPackages">
<Exec Command="dnu restore %(DnxLibraries.FullPath)" ContinueOnError="false"/>
<Exec Command="$(NuGetCommand) install xunit.runner.console -Version 2.1.0 -OutputDirectory $(LibraryRoot)packages" ContinueOnError="false"/>
<Exec Command="$(NuGetCommand) restore $(CodeGeneratorSolution)" ContinueOnError="false" Condition=" '$(Scope)' == 'all' or '$(Scope)' == 'CodeGenerator'" />
</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="Client Runtime Solution : $(ClientRuntimeSolution)" />
<Message Text="Code Generator Solution : $(CodeGeneratorSolution)" />
<Message Text="Source folder : $(LibrarySourceFolder)" />
</Target>
<!-- Conditional import due to a bug in mono related to asterisk -->
<Import Condition=" '$(OS)' == 'Windows_NT'" Project="tools\NuGet.targets"/>
<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>
<Target Name="SignAssembliesInDnxPackages" DependsOnTargets="GetZip">
<ItemGroup>
<_DnxPackages Include="$(LibraryRoot)\dnx\*.nupkg" Exclude="$(LibraryRoot)\dnx\*Tests*.nupkg" />
</ItemGroup>
<PropertyGroup>
<_UnsignedFolder>$(PackageOutputDir)\unsigned</_UnsignedFolder>
<_SignedFolder>$(PackageOutputDir)\signed</_SignedFolder>
</PropertyGroup>
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="SdkPath"/>
</GetFrameworkSdkPath>
<Message Text="%(_DnxPackages.Identity)" Importance="low" />
<RemoveDir Directories="$(_UnsignedFolder);$(_SignedFolder)" ContinueOnError="false" />
<RemoveDir Directories="@(_DnxPackages->'$(PackageOutputDir)\%(Filename)')" ContinueOnError="false" />
<MakeDir Directories="$(_UnsignedFolder);$(_SignedFolder)" />
<Exec Command="$(ZipExe) x -y -scsUTF-8 -o@(_DnxPackages->'$(PackageOutputDir)\%(Filename)') %(_DnxPackages.Identity)" />
<RemoveDir Directories="@(_DnxPackages->'%(RootDir)%(Directory)\%(Filename)\_rels')" />
<Delete Files="@(_DnxPackages->'%(RootDir)%(Directory)\%(Filename)\[Content_Types].xml')" />
<ItemGroup>
<_TempBinaries Include="$(PackageOutputDir)\**\*.dll" />
<_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 SourceFiles="@(_PackageBinaries->'%(SignedFlatFileName)')" DestinationFiles="@(_PackageBinaries->'%(FullPath)')"></Copy>
<Exec Command="$(ZipExe) a -tzip -mx9 -r -y $(PackageOutputDir)\%(_DnxPackages.Filename).nupkg" WorkingDirectory="$(PackageOutputDir)\%(_DnxPackages.Filename)" />
<Delete Files="@(_PackageBinaries->'%(UnsignedFlatFileName)')" />
<Delete Files="@(_PackageBinaries->'%(SignedFlatFileName)')" />
</Target>
</Project>