forked from Azure/azure-libraries-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.proj
306 lines (249 loc) · 14.2 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
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Available Targets:
/t:Clean
Removes temporary build outputs.
/t:Build
Builds assemblies.
/t:Package
Builds NuGet packages using the binaries folder contents.
The packages will drop to .\binaries\packages.
/t:Test
Runs tests
/t:Publish
Publishes the built packages. You will need to include your
publishing key when running. Include: /p:NuGetKey=YOUR_PUBLISHING_KEY
Properties of interest:
/p:Scope
'Common' : build Azure Common
'Subfolder under /src, with solution files, such as 'ResourceManagement\Compute'': build individual packages
'Authentication': build Authentication
By default, it builds all.
/P:CodeSign=True
Code sign binaries, mainly for official release. Default is false.
/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:NuGetPublishingSource=Uri
The NuGet Server to push packages to.
-->
<PropertyGroup>
<LibraryRoot>$(MSBuildThisFileDirectory)</LibraryRoot>
<LibrarySourceFolder>$(LibraryRoot)src</LibrarySourceFolder>
<LibraryToolsFolder>$(LibraryRoot)tools</LibraryToolsFolder>
<SamplesFolder>$(LibraryRoot)Samples</SamplesFolder>
<SamplesTestsFolder>$(LibraryRoot)Samples\Tests</SamplesTestsFolder>
<LibraryNugetPackageFolder>$(LibraryRoot)\packages</LibraryNugetPackageFolder>
<LibraryFriendlyName>Microsoft Azure Management Libraries</LibraryFriendlyName>
<ManagementLibrariesSolution>AzureManagementLibraries.sln</ManagementLibrariesSolution>
<BinariesFolder>$(LibraryRoot)binaries</BinariesFolder>
<PackageOutputDir>$(BinariesFolder)\packages</PackageOutputDir>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<CodeSign Condition=" '$(CodeSign)' == '' ">false</CodeSign>
<!--Set this true only if you want to test the code sign workflow locally-->
<DelaySign Condition =" '$(DelaySign)' == '' ">false</DelaySign>
<Scope Condition=" '$(Scope)' == '' ">All</Scope>
<FxTargetList>portable;net40;net45</FxTargetList>
<ZipExeFolder>$(LibraryToolsFolder)\7-Zip</ZipExeFolder>
<ZipExe>$(ZipExeFolder)\7z.exe</ZipExe>
</PropertyGroup>
<ItemGroup>
<LibraryFxTargetList Include="$(FxTargetList)" />
<AutoRestLibraryFxTargetList Include="portable;net45" />
</ItemGroup>
<PropertyGroup>
<NuGetCommand>"$(LibraryToolsFolder)\nuget.exe"</NuGetCommand>
</PropertyGroup>
<UsingTask TaskName="ValidateStrongNameSignatureTask" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />
<UsingTask TaskName="FilterOutAutoRestLibraries" AssemblyFile="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks.dll" />
<!--
CI build related
-->
<PropertyGroup>
<!--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) " Project="$(CIToolsPath)\Microsoft.WindowsAzure.Build.OnPremise.msbuild" />
<Target Name="PrepareForAutoRestLibraries">
<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="Build" DependsOnTargets="BuildMsBuildTask;PrepareForAutoRestLibraries">
<PropertyGroup>
<_ExtraPropertyList>CodeSign=$(CodeSign)</_ExtraPropertyList>
<_TemporaryNetCoreFeeds>-s https://api.nuget.org/v3/index.json -s https://dotnet.myget.org/F/cli-deps/api/v3/index.json</_TemporaryNetCoreFeeds>
</PropertyGroup>
<CallTarget Targets="BuildServerPreparation" Condition=" '$(CodeSign)' == 'true' " />
<Exec Command="dotnet --info" WorkingDirectory="$(LibraryRoot)" />
<Exec Command="dotnet restore Fluent.SDK.sln" WorkingDirectory="$(LibraryRoot)" />
<Exec Command="dotnet restore Fluent.Samples.sln" WorkingDirectory="$(LibraryRoot)" Condition=" '$(Configuration)' != 'Release' "/>
<Exec Command="dotnet restore Fluent.Tests.sln" WorkingDirectory="$(LibraryRoot)" Condition=" '$(Configuration)' != 'Release' "/>
<CallTarget Targets="BuildNetCoreLibraries" />
<CallTarget Targets="CodeSignBinaries" Condition=" '$(CodeSign)' == 'true' " />
</Target>
<Target Name="BuildNetCoreLibraries">
<Exec Command="dotnet build Fluent.SDK.sln --configuration $(Configuration)"/>
<Exec Command="dotnet build Fluent.Samples.sln --configuration $(Configuration)" Condition=" '$(Configuration)' != 'Release' "/>
<Exec Command="dotnet build Fluent.Tests.sln --configuration $(Configuration)" Condition=" '$(Configuration)' != 'Release' "/>
</Target>
<Target Name="Clean" DependsOnTargets="BuildMsBuildTask;PrepareForAutoRestLibraries;">
<RemoveDir Directories="$(BinariesFolder)" />
</Target>
<Target Name="Test" DependsOnTargets="PrepareForAutoRestLibraries">
<MakeDir Directories="$(LibraryRoot)TestResults"/>
<!--Based on https://github.com/xunit/xunit/issues/653, only xml is supported -->
<Exec Command="dotnet test Tests\Fluent.Tests\Fluent.Tests.csproj -l "trx;LogFileName=$(MSBuildProjectDirectory)\TestResults\Fluent.Tests.trx""
WorkingDirectory="$(LibraryRoot)"
Condition=" $(ExcludeTests) != 'unit' "/>
<Exec Command="dotnet test Tests\Samples.Tests\Samples.Tests.csproj -l "trx;LogFileName=$(MSBuildProjectDirectory)\TestResults\Sample.Tests.trx""
WorkingDirectory="$(LibraryRoot)"
Condition=" $(ExcludeTests) != 'sample' "/>
</Target>
<PropertyGroup>
<!--This property is used by build script at CI server. Do not remove it unless you will update CI as well -->
<!--TODO: research to include all library folders but exlude test folders with huge recorded json files.
For now we run subset of folders to avoid long build delay and avoid errors reported on recorded json files-->
<CorporateScanPaths>$(LibrarySourceFolder)</CorporateScanPaths>
<!--public token associated with MSSharedLibKey.snk-->
<StrongNameToken Condition=" '$(StrongNameToken)' == '' ">31bf3856ad364e35</StrongNameToken>
</PropertyGroup>
<Target Name="SignBinariesForAFxTarget">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath"/>
</GetFrameworkSdkPath>
<ItemGroup>
<DelaySignedAssembliesToValidate Include="binaries\$(LibraryFxTarget)\unsigned\*.dll" />
</ItemGroup>
<Message Importance="high" Text="Binaries\$(LibraryFxTarget)\unsigned contains no files. Code sign will skip."
Condition="'@(DelaySignedAssembliesToValidate)' == ''" />
<ValidateStrongNameSignatureTask
WindowsSdkPath="$(WindowsSdkPath)"
Assembly="%(DelaySignedAssembliesToValidate.Identity)"
ExpectedTokenSignature="$(StrongNameToken)"
ExpectedDelaySigned="true"
ContinueOnError="false"
Condition="'@(DelaySignedAssembliesToValidate)' != ''"/>
<CodeSigningTask
Description="Microsoft Azure SDK"
Keywords="Microsoft Azure .NET SDK"
UnsignedFiles="@(DelaySignedAssembliesToValidate)"
DestinationPath="binaries\$(LibraryFxTarget)"
SigningLogPath="binaries\$(LibraryFxTarget)\signing.log"
ToolsPath="$(CIToolsPath)"
Condition="!$(DelaySign) and '@(DelaySignedAssembliesToValidate)' != ''"/>
<!--If we are testing locally then we copy the binaries and do not submit to the code sign server-->
<Copy SourceFiles="@(DelaySignedAssembliesToValidate)" DestinationFolder="binaries\$(LibraryFxTarget)" Condition="$(DelaySign)" />
<ItemGroup>
<AfterSignedAssembliesToValidate Include="binaries\$(LibraryFxTarget)\*.dll" />
</ItemGroup>
<ValidateStrongNameSignatureTask
WindowsSdkPath="$(WindowsSdkPath)"
Assembly="%(AfterSignedAssembliesToValidate.Identity)"
ExpectedTokenSignature="$(StrongNameToken)"
ExpectedDelaySigned="false"
ContinueOnError="false"
Condition="!$(DelaySign) and '@(DelaySignedAssembliesToValidate)' != ''"/>
<RemoveDir Directories="binaries\$(LibraryFxTarget)\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" />
<Message Text="Signing project: $(MSBuildProjectFullPath)" />
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="SignBinariesForAFxTarget"
Properties="LibraryFxTarget=%(LibraryFxTargetList.Identity);StrongNameToken=$(StrongNameToken)">
</MSBuild>
<CallTarget Targets="ValidateCorporateCompliance" Condition="!$(DelaySign)"/>
</Target>
<!--
Pre-build the tasks file used for validating strong name signatures,
providing date-based build numbers, and processing regular expression
replacements in files such as NuGet specs.
-->
<Target Name="BuildMsBuildTask">
<MSBuild Projects="$(LibraryToolsFolder)\Microsoft.WindowsAzure.Build.Tasks\Microsoft.WindowsAzure.Build.Tasks.csproj"
Targets="Build"
Properties="Configuration=Debug;Platform=AnyCPU" />
</Target>
<!--
We have some important work to do when building our official Library bits.
-->
<Target Name="ValidateCorporateCompliance">
<Error Text="This target must be run in an on-premise build server." Condition=" '$(OnPremiseBuild)'=='false' " />
<CallTarget Targets="CorporateValidation" />
</Target>
<!--
Tasks that should be performed on any build server before getting to work.
-->
<Target Name="BuildServerPreparation">
<!-- Log server information -->
<Message Text="Build Server Information" Importance="high" />
<Message Text="Hostname : $(COMPUTERNAME)" />
<Message Text="Build Account : $(USERDOMAIN)\$(USERNAME)" />
<!-- Useful variables to log -->
<Message Text="Build Properties and Variables" Importance="high" />
<Message Text="Libraries Solution : $(ManagementLibrariesSolution)" />
<Message Text="Library : $(LibraryFriendlyName)" />
<Message Text="Source folder : $(LibrarySourceFolder)" />
</Target>
<Import Project="$(LibraryToolsFolder)\nuget.targets" />
<Target Name="SignAssembliesInNetCorePackages">
<ItemGroup>
<_NetCorePackagesTemp Include="$(PackageOutputDir)\%(NetCore_AutoRestLibraries.PackageName)*.nupkg"/>
</ItemGroup>
<RemoveDuplicates Inputs="@(_NetCorePackagesTemp)">
<Output TaskParameter="Filtered" ItemName="_NetCorePackages" />
</RemoveDuplicates>
<PropertyGroup>
<_UnsignedFolder>$(PackageOutputDir)\unsigned</_UnsignedFolder>
<_SignedFolder>$(PackageOutputDir)\signed</_SignedFolder>
</PropertyGroup>
<Message Text="%(_NetCorePackages.Identity)" Importance="low" />
<RemoveDir Directories="$(_UnsignedFolder);$(_SignedFolder)" ContinueOnError="false" />
<RemoveDir Directories="@(_NetCorePackages->'$(PackageOutputDir)\%(Filename)')" ContinueOnError="false" />
<MakeDir Directories="$(_UnsignedFolder);$(_SignedFolder)" />
<Exec Command="$(ZipExe) x -y -scsUTF-8 -o@(_NetCorePackages->'$(PackageOutputDir)\%(Filename)') %(_NetCorePackages.Identity)" />
<RemoveDir Directories="@(_NetCorePackages->'%(RootDir)%(Directory)\%(Filename)\_rels')" />
<Delete Files="@(_NetCorePackages->'%(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>
<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
WindowsSdkPath="$(WindowsSdkPath)"
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)\%(_NetCorePackages.Filename).nupkg" WorkingDirectory="$(PackageOutputDir)\%(_NetCorePackages.Filename)" />
</Target>
</Project>