@@ -18,10 +18,16 @@ Parameters:
1818 -xamarintests: Runs Xamarin tests. Requires additional SDKs and prerequisite configuration.
1919 -configuration {Debug|Release}
2020 -verbosity: Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
21- . NOTES
21+
2222Build will automatically detect if the machine is Windows vs Unix. On Windows development boxes, additional testing on .NET Framework will be performed.
2323
24- . EXAMPLE
24+ The following environment variables can tune the build behavior:
25+ - AZURE_IOT_DONOTSIGN: disables delay-signing if set to 'TRUE'
26+ - AZURE_IOT_LOCALPACKAGES: the path to the local nuget source.
27+ Add a new source using: `nuget sources add -name MySource -Source <path>`
28+ Remove a source using: `nuget sources remove -name MySource`
29+
30+ . EXAMPLE
2531.\build
2632
2733Builds a Debug version of the SDK.
@@ -50,10 +56,30 @@ Param(
5056 [switch ] $e2etests ,
5157 [switch ] $stresstests ,
5258 [switch ] $xamarintests ,
59+ [switch ] $sign ,
5360 [string ] $configuration = " Debug" ,
5461 [string ] $verbosity = " q"
5562)
5663
64+ Function IsWindowsDevelopmentBox ()
65+ {
66+ return ([Environment ]::OSVersion.Platform -eq [System.PlatformID ]::Win32NT)
67+ }
68+
69+ Function CheckSignTools ()
70+ {
71+ $commands = $ (" SignDotNetBinary" , " SignBinary" , " SignNuGetPackage" , " SignMSIPackage" )
72+
73+ foreach ($command in $commands )
74+ {
75+ $info = Get-Command $command - ErrorAction SilentlyContinue
76+ if ($info -eq $null )
77+ {
78+ throw " Sign toolset not found: '$command ' is missing."
79+ }
80+ }
81+ }
82+
5783Function BuildProject ($path , $message ) {
5884
5985 $label = " BUILD: --- $message $configuration ---"
@@ -81,14 +107,30 @@ Function BuildPackage($path, $message) {
81107
82108 Write-Host
83109 Write-Host - ForegroundColor Cyan $label
84- cd (Join-Path $rootDir $path )
85110
86- $frameworkArgs = " "
111+ $projectPath = Join-Path $rootDir $path
112+ cd $projectPath
87113
88- & dotnet pack -- verbosity $verbosity -- configuration $configuration -- no- build -- include- symbols -- include- source -- output $localPackages
114+ $projectName = (dir (Join-Path $projectPath * .csproj))[0 ].BaseName
115+
116+ if ($sign )
117+ {
118+ Write-Host - ForegroundColor Magenta " `t Signing binaries: $projectName "
119+ $filesToSign = dir - Recurse .\bin\Release\$projectName.dll
120+ SignDotNetBinary $filesToSign
121+ }
89122
123+ & dotnet pack -- verbosity $verbosity -- configuration $configuration -- no- build -- include- symbols -- include- source -- output $localPackages
124+
90125 if ($LASTEXITCODE -ne 0 ) {
91- throw " Build failed: $label "
126+ throw " Package failed: $label "
127+ }
128+
129+ if ($sign )
130+ {
131+ Write-Host - ForegroundColor Magenta " `t Signing package: $projectName "
132+ $filesToSign = dir (Join-Path $localPackages " $projectName .nupkg" )
133+ SignNuGetPackage $filesToSign
92134 }
93135}
94136
@@ -122,47 +164,34 @@ Function RunApp($path, $message, $framework="netcoreapp2.0") {
122164 }
123165}
124166
125- Function IsWindowsDevelopmentBox ()
126- {
127- return ([Environment ]::OSVersion.Platform -eq [System.PlatformID ]::Win32NT)
128- }
129-
130167$rootDir = (Get-Item - Path " .\" - Verbose).FullName
131168$localPackages = Join-Path $rootDir " bin\pkg"
132169$startTime = Get-Date
133170$buildFailed = $true
134171$errorMessage = " "
135172
136173try {
174+ if ($sign )
175+ {
176+ CheckSignTools
177+ }
178+
137179 if (-not $nobuild )
138180 {
139181 # SDK binaries
140182 BuildProject shared\src " Shared Assembly"
141183 BuildProject iothub\device\src " IoT Hub DeviceClient SDK"
142- BuildProject iothub\service\src " IoT Hub ServiceClient SDK"
184+ BuildProject iothub\service\src " IoT Hub ServiceClient SDK"
143185 BuildProject security\tpm\src " SecurityProvider for TPM"
144186 BuildProject provisioning\device\src " Provisioning Device Client SDK"
145187 BuildProject provisioning\transport\amqp\src " Provisioning Transport for AMQP"
146188 BuildProject provisioning\transport\http\src " Provisioning Transport for HTTP"
147189 BuildProject provisioning\transport\mqtt\src " Provisioning Transport for MQTT"
148190 BuildProject provisioning\service\src " Provisioning Service Client SDK"
149-
150- # Samples
151- BuildProject iothub\device\samples " IoT Hub DeviceClient Samples"
152- BuildProject iothub\service\samples " IoT Hub ServiceClient Samples"
153- BuildProject provisioning\device\samples " Provisioning Device Client Samples"
154- BuildProject provisioning\service\samples " Provisioning Service Client Samples"
155- BuildProject security\tpm\samples " SecurityProvider for TPM Samples"
156-
157- # Xamarin samples (require Android, iOS and UWP SDKs and configured iOS remote)
158- if ($xamarintests )
159- {
160- # TODO #335 - create new Xamarin automated samples/tests
161- }
162191 }
163192
164193 # Unit Tests require InternalsVisibleTo and can only run in Debug builds.
165- if ((-not $nounittests ) -and ($configuration.ToLower () -eq " debug " ))
194+ if ((-not $nounittests ) -and ($configuration.ToUpperInvariant () -eq " DEBUG " ))
166195 {
167196 Write-Host
168197 Write-Host - ForegroundColor Cyan " Unit Test execution"
@@ -177,7 +206,7 @@ try {
177206 RunTests security\tpm\tests " SecurityProvider for TPM Tests"
178207 RunTests provisioning\service\tests " Provisioning Service Client Tests"
179208 }
180-
209+
181210 if ((-not $nopackage ))
182211 {
183212 BuildPackage shared\src " Shared Assembly"
@@ -191,6 +220,25 @@ try {
191220 BuildPackage provisioning\service\src " Provisioning Service Client SDK"
192221 }
193222
223+ if (-not [string ]::IsNullOrWhiteSpace($env: AZURE_IOT_LOCALPACKAGES ))
224+ {
225+ Write-Host
226+ Write-Host - ForegroundColor Cyan " Preparing local package source"
227+ Write-Host
228+
229+ if (-not (Test-Path $env: AZURE_IOT_LOCALPACKAGES ))
230+ {
231+ throw " Local NuGet package source path invalid: $ ( $env: AZURE_IOT_LOCALPACKAGES ) "
232+ }
233+
234+ # Clear the NuGet cache and the old packages.
235+ dotnet nuget locals -- clear all
236+ Remove-Item $env: AZURE_IOT_LOCALPACKAGES \* .*
237+
238+ # Copy new packages.
239+ copy (Join-Path $rootDir " bin\pkg\*.*" ) $env: AZURE_IOT_LOCALPACKAGES
240+ }
241+
194242 if ($e2etests )
195243 {
196244 Write-Host
@@ -200,7 +248,7 @@ try {
200248 # Override verbosity to display individual test execution.
201249 $oldVerbosity = $verbosity
202250 $verbosity = " normal"
203-
251+
204252 RunTests e2e\test " End-to-end tests (NetCoreApp)"
205253 if (IsWindowsDevelopmentBox)
206254 {
@@ -209,6 +257,19 @@ try {
209257 }
210258
211259 $verbosity = $oldVerbosity
260+
261+ # Samples
262+ BuildProject iothub\device\samples " IoT Hub DeviceClient Samples"
263+ BuildProject iothub\service\samples " IoT Hub ServiceClient Samples"
264+ BuildProject provisioning\device\samples " Provisioning Device Client Samples"
265+ BuildProject provisioning\service\samples " Provisioning Service Client Samples"
266+ BuildProject security\tpm\samples " SecurityProvider for TPM Samples"
267+
268+ # Xamarin samples (require Android, iOS and UWP SDKs and configured iOS remote)
269+ if ($xamarintests )
270+ {
271+ # TODO #335 - create new Xamarin automated samples/tests
272+ }
212273 }
213274
214275 if ($stresstests )
0 commit comments