From f6ab28d972d033eb361a22f8854c7251b72d6bc4 Mon Sep 17 00:00:00 2001 From: Canhua Li Date: Mon, 30 Dec 2019 12:28:39 -0800 Subject: [PATCH] Allow UAP SDK to be in other folder other than ProgramFiles (#3815) * check UAP in SDK10 installation folder --- ...ve-windows-2019-12-20-14-28-11-master.json | 8 +++++ .../runWindows/utils/msbuildtools.js | 33 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 change/react-native-windows-2019-12-20-14-28-11-master.json diff --git a/change/react-native-windows-2019-12-20-14-28-11-master.json b/change/react-native-windows-2019-12-20-14-28-11-master.json new file mode 100644 index 00000000000..3bbf0606731 --- /dev/null +++ b/change/react-native-windows-2019-12-20-14-28-11-master.json @@ -0,0 +1,8 @@ +{ + "type": "none", + "comment": "supports SDK installed in other folder", + "packageName": "react-native-windows", + "email": "licanhua@live.com", + "commit": "9499a1d3b2f07a984e1dea233623cb06d8a47e6f", + "date": "2019-12-20T22:28:11.758Z" +} \ No newline at end of file diff --git a/vnext/local-cli/runWindows/utils/msbuildtools.js b/vnext/local-cli/runWindows/utils/msbuildtools.js index a45d78dbed2..802f7f9a87a 100644 --- a/vnext/local-cli/runWindows/utils/msbuildtools.js +++ b/vnext/local-cli/runWindows/utils/msbuildtools.js @@ -20,6 +20,7 @@ const { newSuccess, newError, } = require('./commandWithProgress'); +const execSync = require('child_process').execSync; const MSBUILD_VERSIONS = ['16.0', '15.0', '14.0', '12.0', '4.0']; @@ -244,6 +245,27 @@ module.exports.findAvailableVersion = function(buildArch, verbose) { return msbuildTools; }; +function getSDK10InstallationFolder() { + const folder = ''; + + const execString = + 'reg query "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0" /s /v InstallationFolder /reg:32'; + let output; + try { + output = execSync(execString).toString(); + } catch (e) { + return folder; + } + + const re = /\\Microsoft SDKs\\Windows\\v10.0\s*InstallationFolder\s+REG_SZ\s+(.*)/gim; + const match = re.exec(output); + if (match) { + return match[1]; + } + + return folder; +} + module.exports.getAllAvailableUAPVersions = function() { const results = []; @@ -254,13 +276,22 @@ module.exports.getAllAvailableUAPVersions = function() { return results; } - const uapFolderPath = path.join( + let uapFolderPath = path.join( programFilesFolder, 'Windows Kits', '10', 'Platforms', 'UAP', ); + + if (!shell.test('-e', uapFolderPath)) { + // Check other installation folder from reg + const sdkFolder = getSDK10InstallationFolder(); + if (sdkFolder) { + uapFolderPath = path.join(sdkFolder, 'Platforms', 'UAP'); + } + } + // No UAP SDK exists on this machine if (!shell.test('-e', uapFolderPath)) { return results;