Skip to content

Commit ec357c9

Browse files
author
David Kline
authored
Merge pull request #2127 from StephenHodgson/MRTK-May18-BuildPort
Ported some build fixes from dev branch
2 parents e9727f1 + e8e5ae6 commit ec357c9

File tree

15 files changed

+202
-308
lines changed

15 files changed

+202
-308
lines changed

Assets/HoloToolkit-Examples/SharingWithUNET/Scripts/GenericNetworkTransmitter.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
using HoloToolkit.Unity;
54
using System;
65
using System.Collections.Generic;
76
using UnityEngine;
87

9-
#if !UNITY_EDITOR && UNITY_WSA
8+
#if !UNITY_EDITOR && UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
109
using Windows.Networking.Sockets;
1110
using Windows.Storage.Streams;
1211
using Windows.Networking;
@@ -30,10 +29,6 @@ public class GenericNetworkTransmitter : Singleton<GenericNetworkTransmitter>
3029
/// <param name="data">The data that arrived.</param>
3130
public delegate void OnDataReady(byte[] data);
3231

33-
#if UNITY_WSA
34-
public event OnDataReady DataReadyEvent;
35-
#endif
36-
3732
/// <summary>
3833
/// The server to connect to when data is needed.
3934
/// </summary>
@@ -49,7 +44,7 @@ public class GenericNetworkTransmitter : Singleton<GenericNetworkTransmitter>
4944
/// </summary>
5045
private byte[] mostRecentDataBuffer;
5146

52-
#if !UNITY_EDITOR && UNITY_WSA
47+
#if !UNITY_EDITOR && UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
5348
/// <summary>
5449
/// Tracks the network connection to the remote machine we are sending meshes to.
5550
/// </summary>
@@ -64,6 +59,8 @@ public class GenericNetworkTransmitter : Singleton<GenericNetworkTransmitter>
6459
/// If we cannot connect to the server, this is how long we will wait before retrying.
6560
/// </summary>
6661
private float timeToDeferFailedConnections = 10.0f;
62+
63+
public event OnDataReady DataReadyEvent;
6764
#endif
6865

6966
/// <summary>
@@ -107,7 +104,7 @@ private void Update()
107104
}
108105

109106
// A lot of the work done in this class can only be done in UWP. The editor is not a UWP app.
110-
#if !UNITY_EDITOR && UNITY_WSA
107+
#if !UNITY_EDITOR && UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
111108
private void RequestDataRetry()
112109
{
113110
if (!RequestAndGetData())
@@ -122,7 +119,7 @@ private void RequestDataRetry()
122119
/// </summary>
123120
public void ConfigureAsServer()
124121
{
125-
#if !UNITY_EDITOR && UNITY_WSA
122+
#if !UNITY_EDITOR && UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
126123
Task t = new Task(() =>
127124
{
128125
networkListener = new StreamSocketListener();
@@ -143,7 +140,7 @@ public void ConfigureAsServer()
143140
/// </summary>
144141
private bool ConnectListener()
145142
{
146-
#if !UNITY_EDITOR && UNITY_WSA
143+
#if !UNITY_EDITOR && UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
147144
if (waitingForConnection)
148145
{
149146
Debug.Log("Not a good time to connect listener");
@@ -165,7 +162,7 @@ private bool ConnectListener()
165162
#endif
166163
}
167164

168-
#if !UNITY_EDITOR && UNITY_WSA
165+
#if !UNITY_EDITOR && UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
169166
/// <summary>
170167
/// When a connection is made to us, this call back gets called and
171168
/// we send our data.

Assets/HoloToolkit-Examples/SharingWithUNET/Scripts/UNetAnchorManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void Start()
187187
return;
188188
}
189189

190-
#if UNITY_WSA
190+
#if UNITY_WSA && (!ENABLE_IL2CPP && NET_STANDARD_2_0)
191191
#if UNITY_2017_2_OR_NEWER
192192
if (HolographicSettings.IsDisplayOpaque)
193193
#else

Assets/HoloToolkit/BuildAndDeploy/Editor/BuildDeployTools.cs

+68-30
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,21 @@ public static bool BuildSLN(string buildDirectory, bool showDialog = true)
8585
WSAUwpSdk = EditorUserBuildSettings.wsaUWPSDK,
8686

8787
// 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
8896
PostBuildAction = (innerBuildInfo, buildError) =>
8997
{
9098
if (!string.IsNullOrEmpty(buildError))
9199
{
92-
EditorUtility.DisplayDialog(PlayerSettings.productName + " WindowsStoreApp Build Failed!", buildError, "OK");
100+
EditorUtility.DisplayDialog(string.Format("{0} WindowsStoreApp Build Failed!", PlayerSettings.productName), buildError, "OK");
93101
}
102+
#endif
94103
else
95104
{
96105
if (showDialog)
@@ -223,7 +232,7 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
223232

224233
if (!File.Exists(msBuildPath))
225234
{
226-
Debug.LogErrorFormat("MSBuild.exe is missing or invalid (path={0}).", msBuildPath);
235+
Debug.LogErrorFormat("MSBuild.exe is missing or invalid:\n{0}.", msBuildPath);
227236
EditorUtility.ClearProgressBar();
228237
return false;
229238
}
@@ -240,13 +249,12 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
240249
File.Copy(unity + @"\Data\PlaybackEngines\MetroSupport\Tools\project.json", storePath + "\\project.json");
241250
}
242251

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);
246254
bool restoreFirstPass = Directory.Exists(assemblyCSharpFirstPass);
255+
string nugetPath = Path.Combine(unity, @"Data\PlaybackEngines\MetroSupport\Tools\NuGet.exe");
247256

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
250258
if (PlayerSettings.GetScriptingBackend(BuildTargetGroup.WSA) == ScriptingImplementation.WinRTDotNET &&
251259
(!RestoreNugetPackages(nugetPath, storePath) ||
252260
!RestoreNugetPackages(nugetPath, storePath + "\\" + productName) ||
@@ -260,63 +268,92 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
260268

261269
EditorUtility.DisplayProgressBar("Build AppX", "Building AppX Package...", 25);
262270

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))
266273
{
267-
IncrementPackageVersion();
274+
Debug.LogError("Failed to increment package version!");
275+
EditorUtility.ClearProgressBar();
276+
return false;
268277
}
269278

270279
// Now do the actual build
271280
var pInfo = new ProcessStartInfo
272281
{
273282
FileName = msBuildPath,
274-
CreateNoWindow = false,
283+
CreateNoWindow = true,
284+
UseShellExecute = false,
285+
RedirectStandardOutput = true,
286+
RedirectStandardError = true,
275287
Arguments = string.Format("\"{0}\" /t:{1} /p:Configuration={2} /p:Platform={3} /verbosity:m",
276288
solutionProjectPath,
277289
forceRebuildAppx ? "Rebuild" : "Build",
278290
buildConfig,
279291
buildPlatform)
280292
};
281293

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+
};
286299

287300
try
288301
{
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+
289318
if (!process.Start())
290319
{
291-
Debug.LogError("Failed to start Cmd process!");
320+
Debug.LogError("Failed to start process!");
292321
EditorUtility.ClearProgressBar();
322+
process.Close();
323+
process.Dispose();
293324
return false;
294325
}
295326

327+
process.BeginOutputReadLine();
328+
process.BeginErrorReadLine();
296329
process.WaitForExit();
297330

298331
EditorUtility.ClearProgressBar();
299332

300-
if (process.ExitCode == 0 &&
301-
showDialog &&
333+
if (process.ExitCode == 0 && showDialog &&
302334
!EditorUtility.DisplayDialog("Build AppX", "AppX Build Successful!", "OK", "Open AppX Folder"))
303335
{
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));
305337
}
306338

307339
if (process.ExitCode != 0)
308340
{
309-
Debug.LogError("MSBuild error (code = " + process.ExitCode + ")");
341+
Debug.LogError(string.Format("MSBuild error (code = {0})", process.ExitCode));
342+
EditorUtility.ClearProgressBar();
310343
EditorUtility.DisplayDialog(PlayerSettings.productName + " build Failed!", "Failed to build appx from solution. Error code: " + process.ExitCode, "OK");
344+
345+
process.Close();
346+
process.Dispose();
311347
return false;
312348
}
313349

314350
process.Close();
315351
process.Dispose();
316-
317352
}
318353
catch (Exception e)
319354
{
355+
process.Close();
356+
process.Dispose();
320357
Debug.LogError("Cmd Process EXCEPTION: " + e);
321358
EditorUtility.ClearProgressBar();
322359
return false;
@@ -325,15 +362,15 @@ public static bool BuildAppxFromSLN(string productName, string msBuildVersion, b
325362
return true;
326363
}
327364

328-
private static void IncrementPackageVersion()
365+
private static bool SetPackageVersion(bool increment)
329366
{
330367
// Find the manifest, assume the one we want is the first one
331368
string[] manifests = Directory.GetFiles(BuildDeployPrefs.AbsoluteBuildDirectory, "Package.appxmanifest", SearchOption.AllDirectories);
332369

333370
if (manifests.Length == 0)
334371
{
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;
337374
}
338375

339376
string manifest = manifests[0];
@@ -342,8 +379,8 @@ private static void IncrementPackageVersion()
342379

343380
if (identityNode == null)
344381
{
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;
347384
}
348385

349386
// We use XName.Get instead of string -> XName implicit conversion because
@@ -353,20 +390,21 @@ private static void IncrementPackageVersion()
353390

354391
if (versionAttr == null)
355392
{
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;
358395
}
359396

360397
// Assume package version always has a '.' between each number.
361398
// According to https://msdn.microsoft.com/en-us/library/windows/apps/br211441.aspx
362399
// Package versions are always of the form Major.Minor.Build.Revision.
363400
// Note: Revision number reserved for Windows Store, and a value other than 0 will fail WACK.
364401
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);
366403

367404
PlayerSettings.WSA.packageVersion = newVersion;
368405
versionAttr.Value = newVersion.ToString();
369406
rootNode.Save(manifest);
407+
return true;
370408
}
371409
}
372410
}

0 commit comments

Comments
 (0)