@@ -85,12 +85,21 @@ public static bool BuildSLN(string buildDirectory, bool showDialog = true)
85
85
WSAUwpSdk = EditorUserBuildSettings . wsaUWPSDK ,
86
86
87
87
// Configure a post build action that will compile the generated solution
88
+ #if UNITY_2018_1_OR_NEWER
89
+ PostBuildAction = ( innerBuildInfo , buildReport ) =>
90
+ {
91
+ if ( buildReport . summary . result != UnityEditor . Build . Reporting . BuildResult . Succeeded )
92
+ {
93
+ EditorUtility . DisplayDialog ( string . Format ( "{0} WindowsStoreApp Build {1}!" , PlayerSettings . productName , buildReport . summary . result ) , "See console for details" , "OK" ) ;
94
+ }
95
+ #else
88
96
PostBuildAction = ( innerBuildInfo , buildError ) =>
89
97
{
90
98
if ( ! string . IsNullOrEmpty ( buildError ) )
91
99
{
92
- EditorUtility . DisplayDialog ( PlayerSettings . productName + " WindowsStoreApp Build Failed!", buildError , "OK" ) ;
100
+ EditorUtility . DisplayDialog ( string . Format ( "{0} WindowsStoreApp Build Failed!", PlayerSettings . productName ) , buildError , "OK" ) ;
93
101
}
102
+ #endif
94
103
else
95
104
{
96
105
if ( showDialog )
@@ -223,7 +232,7 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
223
232
224
233
if ( ! File . Exists ( msBuildPath ) )
225
234
{
226
- Debug . LogErrorFormat ( "MSBuild.exe is missing or invalid (path= {0}) ." , msBuildPath ) ;
235
+ Debug . LogErrorFormat ( "MSBuild.exe is missing or invalid: \n {0}." , msBuildPath ) ;
227
236
EditorUtility . ClearProgressBar ( ) ;
228
237
return false ;
229
238
}
@@ -240,13 +249,12 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
240
249
File . Copy ( unity + @"\Data\PlaybackEngines\MetroSupport\Tools\project.json" , storePath + "\\ project.json" ) ;
241
250
}
242
251
243
- string nugetPath = Path . Combine ( unity , @"Data\PlaybackEngines\MetroSupport\Tools\NuGet.exe" ) ;
244
- string assemblyCSharp = storePath + "/GeneratedProjects/UWP/Assembly-CSharp" ;
245
- string assemblyCSharpFirstPass = storePath + "/GeneratedProjects/UWP/Assembly-CSharp-firstpass" ;
252
+ string assemblyCSharp = string . Format ( "{0}/GeneratedProjects/UWP/Assembly-CSharp" , storePath ) ;
253
+ string assemblyCSharpFirstPass = string . Format ( "{0}/GeneratedProjects/UWP/Assembly-CSharp-firstpass" , storePath ) ;
246
254
bool restoreFirstPass = Directory . Exists ( assemblyCSharpFirstPass ) ;
255
+ string nugetPath = Path . Combine ( unity , @"Data\PlaybackEngines\MetroSupport\Tools\NuGet.exe" ) ;
247
256
248
- // Before building, need to run a nuget restore to generate a json.lock file. Failing to do
249
- // this breaks the build in VS RTM
257
+ // Before building, need to run a nuget restore to generate a json.lock file. Failing to do this breaks the build in VS RTM
250
258
if ( PlayerSettings . GetScriptingBackend ( BuildTargetGroup . WSA ) == ScriptingImplementation . WinRTDotNET &&
251
259
( ! RestoreNugetPackages ( nugetPath , storePath ) ||
252
260
! RestoreNugetPackages ( nugetPath , storePath + "\\ " + productName ) ||
@@ -260,63 +268,92 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
260
268
261
269
EditorUtility . DisplayProgressBar ( "Build AppX" , "Building AppX Package..." , 25 ) ;
262
270
263
- // Ensure that the generated .appx version increments by modifying
264
- // Package.appxmanifest
265
- if ( incrementVersion )
271
+ // Ensure that the generated .appx version increments by modifying Package.appxmanifest
272
+ if ( ! SetPackageVersion ( incrementVersion ) )
266
273
{
267
- IncrementPackageVersion ( ) ;
274
+ Debug . LogError ( "Failed to increment package version!" ) ;
275
+ EditorUtility . ClearProgressBar ( ) ;
276
+ return false ;
268
277
}
269
278
270
279
// Now do the actual build
271
280
var pInfo = new ProcessStartInfo
272
281
{
273
282
FileName = msBuildPath ,
274
- CreateNoWindow = false ,
283
+ CreateNoWindow = true ,
284
+ UseShellExecute = false ,
285
+ RedirectStandardOutput = true ,
286
+ RedirectStandardError = true ,
275
287
Arguments = string . Format ( "\" {0}\" /t:{1} /p:Configuration={2} /p:Platform={3} /verbosity:m" ,
276
288
solutionProjectPath ,
277
289
forceRebuildAppx ? "Rebuild" : "Build" ,
278
290
buildConfig ,
279
291
buildPlatform )
280
292
} ;
281
293
282
- // Uncomment out to debug by copying into command window
283
- //Debug.Log("\"" + vs + "\"" + " " + pInfo.Arguments);
284
-
285
- var process = new Process { StartInfo = pInfo } ;
294
+ var process = new Process
295
+ {
296
+ StartInfo = pInfo ,
297
+ EnableRaisingEvents = true
298
+ } ;
286
299
287
300
try
288
301
{
302
+ process . ErrorDataReceived += ( sender , args ) =>
303
+ {
304
+ if ( ! string . IsNullOrEmpty ( args . Data ) )
305
+ {
306
+ Debug . LogError ( args . Data ) ;
307
+ }
308
+ } ;
309
+
310
+ process . OutputDataReceived += ( sender , args ) =>
311
+ {
312
+ if ( ! string . IsNullOrEmpty ( args . Data ) )
313
+ {
314
+ Debug . Log ( args . Data ) ;
315
+ }
316
+ } ;
317
+
289
318
if ( ! process . Start ( ) )
290
319
{
291
- Debug . LogError ( "Failed to start Cmd process!" ) ;
320
+ Debug . LogError ( "Failed to start process!" ) ;
292
321
EditorUtility . ClearProgressBar ( ) ;
322
+ process . Close ( ) ;
323
+ process . Dispose ( ) ;
293
324
return false ;
294
325
}
295
326
327
+ process . BeginOutputReadLine ( ) ;
328
+ process . BeginErrorReadLine ( ) ;
296
329
process . WaitForExit ( ) ;
297
330
298
331
EditorUtility . ClearProgressBar ( ) ;
299
332
300
- if ( process . ExitCode == 0 &&
301
- showDialog &&
333
+ if ( process . ExitCode == 0 && showDialog &&
302
334
! EditorUtility . DisplayDialog ( "Build AppX" , "AppX Build Successful!" , "OK" , "Open AppX Folder" ) )
303
335
{
304
- Process . Start ( "explorer.exe" , "/f /open," + Path . GetFullPath ( BuildDeployPrefs . BuildDirectory + "/" + PlayerSettings . productName + "/AppPackages" ) ) ;
336
+ Process . Start ( "explorer.exe" , string . Format ( "/f /open,{0}/{1}/AppPackages" , Path . GetFullPath ( BuildDeployPrefs . BuildDirectory ) , PlayerSettings . productName ) ) ;
305
337
}
306
338
307
339
if ( process . ExitCode != 0 )
308
340
{
309
- Debug . LogError ( "MSBuild error (code = " + process . ExitCode + ")" ) ;
341
+ Debug . LogError ( string . Format ( "MSBuild error (code = {0})" , process . ExitCode ) ) ;
342
+ EditorUtility . ClearProgressBar ( ) ;
310
343
EditorUtility . DisplayDialog ( PlayerSettings . productName + " build Failed!" , "Failed to build appx from solution. Error code: " + process . ExitCode , "OK" ) ;
344
+
345
+ process . Close ( ) ;
346
+ process . Dispose ( ) ;
311
347
return false ;
312
348
}
313
349
314
350
process . Close ( ) ;
315
351
process . Dispose ( ) ;
316
-
317
352
}
318
353
catch ( Exception e )
319
354
{
355
+ process . Close ( ) ;
356
+ process . Dispose ( ) ;
320
357
Debug . LogError ( "Cmd Process EXCEPTION: " + e ) ;
321
358
EditorUtility . ClearProgressBar ( ) ;
322
359
return false ;
@@ -325,15 +362,15 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
325
362
return true ;
326
363
}
327
364
328
- private static void IncrementPackageVersion ( )
365
+ private static bool SetPackageVersion ( bool increment )
329
366
{
330
367
// Find the manifest, assume the one we want is the first one
331
368
string [ ] manifests = Directory . GetFiles ( BuildDeployPrefs . AbsoluteBuildDirectory , "Package.appxmanifest" , SearchOption . AllDirectories ) ;
332
369
333
370
if ( manifests . Length == 0 )
334
371
{
335
- Debug . LogError ( "Unable to find Package.appxmanifest file for build (in path - " + BuildDeployPrefs . AbsoluteBuildDirectory + ")" ) ;
336
- return ;
372
+ Debug . LogError ( string . Format ( "Unable to find Package.appxmanifest file for build (in path - {0})" , BuildDeployPrefs . AbsoluteBuildDirectory ) ) ;
373
+ return false ;
337
374
}
338
375
339
376
string manifest = manifests [ 0 ] ;
@@ -342,8 +379,8 @@ private static void IncrementPackageVersion()
342
379
343
380
if ( identityNode == null )
344
381
{
345
- Debug . LogError ( "Package.appxmanifest for build (in path - " + BuildDeployPrefs . AbsoluteBuildDirectory + " ) is missing an <Identity /> node") ;
346
- return ;
382
+ Debug . LogError ( string . Format ( "Package.appxmanifest for build (in path - {0} ) is missing an <Identity /> node" , BuildDeployPrefs . AbsoluteBuildDirectory ) ) ;
383
+ return false ;
347
384
}
348
385
349
386
// We use XName.Get instead of string -> XName implicit conversion because
@@ -353,20 +390,21 @@ private static void IncrementPackageVersion()
353
390
354
391
if ( versionAttr == null )
355
392
{
356
- Debug . LogError ( "Package.appxmanifest for build (in path - " + BuildDeployPrefs . AbsoluteBuildDirectory + " ) is missing a version attribute in the <Identity /> node.") ;
357
- return ;
393
+ Debug . LogError ( string . Format ( "Package.appxmanifest for build (in path - {0} ) is missing a version attribute in the <Identity /> node." , BuildDeployPrefs . AbsoluteBuildDirectory ) ) ;
394
+ return false ;
358
395
}
359
396
360
397
// Assume package version always has a '.' between each number.
361
398
// According to https://msdn.microsoft.com/en-us/library/windows/apps/br211441.aspx
362
399
// Package versions are always of the form Major.Minor.Build.Revision.
363
400
// Note: Revision number reserved for Windows Store, and a value other than 0 will fail WACK.
364
401
var version = PlayerSettings . WSA . packageVersion ;
365
- var newVersion = new Version ( version . Major , version . Minor , version . Build + 1 , version . Revision ) ;
402
+ var newVersion = new Version ( version . Major , version . Minor , increment ? version . Build + 1 : version . Build , version . Revision ) ;
366
403
367
404
PlayerSettings . WSA . packageVersion = newVersion ;
368
405
versionAttr . Value = newVersion . ToString ( ) ;
369
406
rootNode . Save ( manifest ) ;
407
+ return true ;
370
408
}
371
409
}
372
410
}
0 commit comments