Skip to content

Commit dcd1499

Browse files
authored
Merge pull request #9556 from MaxWang-MS/nuget_restore
Adding the option to use nuget.exe for restore in build tools
2 parents e4c05e3 + b282d6a commit dcd1499

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

Assets/MRTK/Core/Utilities/BuildAndDeploy/UwpAppxBuildTools.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,27 @@ public static async Task<bool> BuildAppxAsync(UwpBuildInfo buildInfo, Cancellati
9090
string storagePath = Path.GetFullPath(Path.Combine(Path.Combine(Application.dataPath, ".."), buildInfo.OutputDirectory));
9191
string solutionProjectPath = Path.GetFullPath(Path.Combine(storagePath, $@"{PlayerSettings.productName}.sln"));
9292

93+
int exitCode;
94+
9395
// Building the solution requires first restoring NuGet packages - when built through
9496
// Visual Studio, VS does this automatically - when building via msbuild like we're doing here,
9597
// we have to do that step manually.
96-
int exitCode = await Run(msBuildPath,
98+
// We use msbuild for nuget restore by default, but if a path to nuget.exe is supplied then we use that executable
99+
if (string.IsNullOrEmpty(buildInfo.NugetExecutablePath))
100+
{
101+
exitCode = await Run(msBuildPath,
97102
$"\"{solutionProjectPath}\" /t:restore {GetMSBuildLoggingCommand(buildInfo.LogDirectory, "nugetRestore.log")}",
98103
!Application.isBatchMode,
99104
cancellationToken);
105+
}
106+
else
107+
{
108+
exitCode = await Run(buildInfo.NugetExecutablePath,
109+
$"restore \"{solutionProjectPath}\"",
110+
!Application.isBatchMode,
111+
cancellationToken);
112+
}
113+
100114
if (exitCode != 0)
101115
{
102116
IsBuilding = false;

Assets/MRTK/Core/Utilities/BuildAndDeploy/UwpBuildDeployPreferences.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static class UwpBuildDeployPreferences
4646
private const string EDITOR_PREF_MULTICORE_APPX_BUILD_ENABLED = "BuildDeployWindow_MulticoreAppxBuildEnabled";
4747
private const string EDITOR_PREF_RESEARCH_MODE_CAPABILITY_ENABLED = "BuildDeployWindow_ResearchModeCapabilityEnabled";
4848
private const string EDITOR_PREF_ALLOW_UNSAFE_CODE = "BuildDeployWindow_AllowUnsafeCode";
49+
private const string EDITOR_PREF_NUGET_EXECUTABLE_PATH = "BuildDeployWindow_NugetExecutablePath";
4950

5051
/// <summary>
5152
/// The current Build Configuration. (Debug, Release, or Master)
@@ -194,5 +195,14 @@ public static bool AllowUnsafeCode
194195
get => EditorPreferences.Get(EDITOR_PREF_ALLOW_UNSAFE_CODE, false);
195196
set => EditorPreferences.Set(EDITOR_PREF_ALLOW_UNSAFE_CODE, value);
196197
}
198+
199+
/// <summary>
200+
/// Current value of the optional path to nuget.exe.
201+
/// </summary>
202+
public static string NugetExecutablePath
203+
{
204+
get => EditorPreferences.Get(EDITOR_PREF_NUGET_EXECUTABLE_PATH, string.Empty);
205+
set => EditorPreferences.Set(EDITOR_PREF_NUGET_EXECUTABLE_PATH, value);
206+
}
197207
}
198208
}

Assets/MRTK/Core/Utilities/BuildAndDeploy/UwpBuildInfo.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,10 @@ public UwpBuildInfo(bool isCommandLine = false) : base(isCommandLine)
5858
/// in the list to the manifest
5959
/// </summary>
6060
public List<string> DeviceCapabilities { get; set; } = null;
61+
62+
/// <summary>
63+
/// Optional path to nuget.exe. Used when performing package restore with nuget.exe (instead of msbuild) is desired.
64+
/// </summary>
65+
public string NugetExecutablePath { get; set; }
6166
}
6267
}

Assets/MRTK/Core/Utilities/BuildAndDeploy/UwpPlayerBuildTools.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ private static void ParseBuildCommandLine(ref UwpBuildInfo buildInfo)
3838
// Note: the min sdk target cannot be changed.
3939
EditorUserBuildSettings.wsaUWPSDK = arguments[++i];
4040
break;
41+
case "-nugetPath":
42+
buildInfo.NugetExecutablePath = arguments[++i];
43+
break;
4144
}
4245
}
4346
}

Assets/MRTK/Tools/BuildWindow/BuildDeployWindow.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ private enum BuildDeployTab
139139

140140
private readonly GUIContent ViewPlayerLogLabel = new GUIContent("View Player Log", "Launch notepad with more recent player log for listed AppX on either currently selected device or from all devices.");
141141

142+
private readonly GUIContent NugetPathLabel = new GUIContent("Nuget Executable Path", "Only set this when restoring packages with nuget.exe (instead of msbuild) is desired.");
143+
142144
#endregion Labels
143145

144146
#region Properties
@@ -563,6 +565,22 @@ private void RenderAppxBuildView()
563565
// since there's a null texture issue when Unity reloads the assets during a build
564566
MixedRealityBuildPreferences.DrawAppLauncherModelField(appxCancellationTokenSource == null);
565567

568+
// Draw the section for nuget executable path
569+
EditorGUILayout.LabelField("Nuget Path (Optional)", EditorStyles.boldLabel);
570+
571+
string nugetExecutablePath = EditorGUILayout.TextField(NugetPathLabel, UwpBuildDeployPreferences.NugetExecutablePath);
572+
using (new EditorGUILayout.HorizontalScope())
573+
{
574+
if (GUILayout.Button("Select Nuget Executable Path"))
575+
{
576+
nugetExecutablePath = EditorUtility.OpenFilePanel(
577+
"Select Nuget Executable Path", "", "exe");
578+
}
579+
if (GUILayout.Button("Use msbuild for Restore & Clear Path"))
580+
{
581+
nugetExecutablePath = "";
582+
}
583+
}
566584
if (c.changed)
567585
{
568586
UwpBuildDeployPreferences.PlatformToolset = PLATFORM_TOOLSET_VALUES[newPlatformToolsetIndex];
@@ -571,6 +589,7 @@ private void RenderAppxBuildView()
571589
UwpBuildDeployPreferences.ResearchModeCapabilityEnabled = researchModeEnabled;
572590
UwpBuildDeployPreferences.ForceRebuild = forceRebuildAppx;
573591
UwpBuildDeployPreferences.MulticoreAppxBuildEnabled = multicoreAppxBuildEnabled;
592+
UwpBuildDeployPreferences.NugetExecutablePath = nugetExecutablePath;
574593
}
575594
}
576595
}

0 commit comments

Comments
 (0)