Skip to content

Commit

Permalink
fix(windows): restore ability to use NuGet
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Mar 30, 2021
1 parent 0a63fbe commit 9a2a340
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ jobs:
- name: Build bundle and create solution
run: |
yarn build:windows
yarn install-windows-test-app
yarn install-windows-test-app --use-nuget
working-directory: example
- name: Install NuGet packages
run: |
Expand Down Expand Up @@ -460,7 +460,7 @@ jobs:
run: |
yarn build:windows
if ("${{ matrix.template }}" -eq "all") { yarn install-windows-test-app }
else { yarn install-windows-test-app --projectDirectory=. }
else { yarn install-windows-test-app --project-directory=. }
working-directory: template-example
- name: Install NuGet packages
run: |
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"react-native": "0.63.4",
"react-native-macos": "0.63.23",
"react-native-test-app": "../",
"react-native-windows": "0.63.24"
"react-native-windows": "0.63.26"
}
}
1 change: 1 addition & 0 deletions example/windows/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ packages/

**/Generated Files/**
*.sln
NuGet.Config
39 changes: 20 additions & 19 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -880,15 +880,16 @@
sudo-prompt "^9.0.0"
wcwidth "^1.0.1"

"@react-native-windows/cli@0.63.10":
version "0.63.10"
resolved "https://registry.npmjs.org/@react-native-windows/cli/-/cli-0.63.10.tgz#d26f54003ebf6fa4909db57d07a765057b35f7b8"
integrity sha512-nCVCN6DKciOtmou71Sj3b30CvQfnD+t9TbSYa8uuGTguB57A3F2gOBl+6fS+r9cAQ5V5mMAX2LWg1YovT8sPcw==
"@react-native-windows/cli@0.63.11":
version "0.63.11"
resolved "https://registry.npmjs.org/@react-native-windows/cli/-/cli-0.63.11.tgz#239c7d905c9198fbbb08b117acb6260d5ce94828"
integrity sha512-RRfeoBwFIIdctcvT8Ynrew7kdYCqnGY/35CrW6M2/G+f3ZVwHhTpdF8I5zyLAQskvFgztRE40MdMofylgcRI0Q==
dependencies:
"@react-native-windows/telemetry" "^0.63.4"
"@react-native-windows/telemetry" "^0.63.5"
chalk "^3.0.0"
cli-spinners "^2.2.0"
envinfo "^7.5.0"
find-up "^4.1.0"
glob "^7.1.1"
inquirer "^3.0.6"
mustache "^4.0.1"
Expand All @@ -899,13 +900,13 @@
username "^5.1.0"
uuid "^3.3.2"
xml-parser "^1.2.1"
xmldom "^0.3.0"
xmldom "^0.5.0"
xpath "^0.0.27"

"@react-native-windows/telemetry@^0.63.4":
version "0.63.4"
resolved "https://registry.npmjs.org/@react-native-windows/telemetry/-/telemetry-0.63.4.tgz#940cffe1cb890ac22c76ba04af2284e1412c7faa"
integrity sha512-jTCLw1JcKVaNbRYq6KJIu72VcJ61a80ZjT6++KDJcLROA6DyRxiX3LhW5anIbV4Ww9vA5CNlU0SUb2pAIw8Jpw==
"@react-native-windows/telemetry@^0.63.5":
version "0.63.5"
resolved "https://registry.npmjs.org/@react-native-windows/telemetry/-/telemetry-0.63.5.tgz#77d3a490b26490a642e7d7ce21cd5c06b768f4be"
integrity sha512-Ifd54IIcGbPjwAGfjJkRfdk5+SNtc9oCWgKMrJszIrlJ1REYVUXBo+6Xw3taKyA1Jf1eCB7DWlb98/NbqdLgcg==
dependencies:
applicationinsights "^1.8.8"

Expand Down Expand Up @@ -3672,13 +3673,13 @@ react-native-test-app@../:
rimraf "^3.0.0"
yargs "^16.0.0"

react-native-windows@0.63.24:
version "0.63.24"
resolved "https://registry.npmjs.org/react-native-windows/-/react-native-windows-0.63.24.tgz#40d6aca2a748ef3985b5942b29d0b05631fecca7"
integrity sha512-N+C3NR4cYM7uOXbhx4sMT3QmjSJ7tPKEJBZOVlieEHJ1Bm0ZyP9Bv7ZKzLeouCA/z78/5NhixIwiJVJ1CPIjMA==
react-native-windows@0.63.26:
version "0.63.26"
resolved "https://registry.npmjs.org/react-native-windows/-/react-native-windows-0.63.26.tgz#af5213c5a0f7ecfd013701531490e9120b9192e4"
integrity sha512-ZbxskcsR+7nJ8uqXnnuZgHHzBB8gZ7RJ556skiTUXlXKs1vh4/PODmSvvNroX/56UXw35/Zi/YtapT/sMqgPJQ==
dependencies:
"@babel/runtime" "^7.8.4"
"@react-native-windows/cli" "0.63.10"
"@react-native-windows/cli" "0.63.11"
abort-controller "^3.0.0"
anser "^1.4.9"
base64-js "^1.1.2"
Expand Down Expand Up @@ -4664,10 +4665,10 @@ xmldom@0.1.x:
resolved "https://registry.npmjs.org/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==

xmldom@^0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/xmldom/-/xmldom-0.3.0.tgz#e625457f4300b5df9c2e1ecb776147ece47f3e5a"
integrity sha512-z9s6k3wxE+aZHgXYxSTpGDo7BYOUfJsIRyoZiX6HTjwpwfS2wpQBQKa2fD+ShLyPkqDYo5ud7KitmLZ2Cd6r0g==
xmldom@^0.5.0:
version "0.5.0"
resolved "https://registry.npmjs.org/xmldom/-/xmldom-0.5.0.tgz#193cb96b84aa3486127ea6272c4596354cb4962e"
integrity sha512-Foaj5FXVzgn7xFzsKeNIde9g6aFBxTPi37iwsno8QvApmtg7KYrr+OPyRHcJF7dud2a5nGRBXK3n0dL62Gf7PA==

xpath@^0.0.27:
version "0.0.27"
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
{
"name": "react-native-test-app",
"license": "MIT",
"author": {
"name": "Microsoft Open Source",
"email": "microsoftopensource@users.noreply.github.com"
},
"bin": {
"configure-test-app": "scripts/configure.js",
"init-test-app": "scripts/init.js",
"install-windows-test-app": "windows/test-app.js"
},
"repository": {
"type": "git",
"url": "https://github.com/microsoft/react-native-test-app.git"
},
"version": "0.0.1-dev",
"description": "react-native-test-app provides a test app for all supported platforms as a package",
"keywords": [
Expand All @@ -29,6 +15,20 @@
"windows"
],
"homepage": "https://github.com/microsoft/react-native-test-app",
"license": "MIT",
"author": {
"name": "Microsoft Open Source",
"email": "microsoftopensource@users.noreply.github.com"
},
"bin": {
"configure-test-app": "scripts/configure.js",
"init-test-app": "scripts/init.js",
"install-windows-test-app": "windows/test-app.js"
},
"repository": {
"type": "git",
"url": "https://github.com/microsoft/react-native-test-app.git"
},
"scripts": {
"ci": "yarn --use-yarnrc .yarnrc-offline --prefer-offline --frozen-lockfile --non-interactive",
"clean": "npx --quiet rimraf example/node_modules/react-native-test-app && git clean -dfqx",
Expand Down Expand Up @@ -88,7 +88,7 @@
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-macos": "0.63.23",
"react-native-windows": "0.63.24",
"react-native-windows": "0.63.26",
"semantic-release": "^17.0.0",
"suggestion-bot": "^1.0.0",
"typescript": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion scripts/set-react-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const profiles = {
react: "17.0.1",
"react-native": "0.64.0",
"react-native-macos": undefined,
"react-native-windows": "0.64.1",
"react-native-windows": "0.64.2",
},
master: {
"@react-native-community/cli": "^5.0.1-alpha.0",
Expand Down
13 changes: 7 additions & 6 deletions windows/ReactTestApp/ReactTestApp.vcxproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="16.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" />
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.props')" />
<PropertyGroup Label="Globals">
<CppWinRTOptimized>true</CppWinRTOptimized>
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
Expand All @@ -22,6 +22,7 @@
<ProjectRootDir Condition="'$(ProjectRootDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'app.json'))</ProjectRootDir>
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
<ReactTestAppDir Condition="'$(ReactTestAppDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'node_modules\react-native-test-app\package.json'))\node_modules\react-native-test-app\windows\ReactTestApp\</ReactTestAppDir>
<UseExperimentalNuget>false</UseExperimentalNuget>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ARM">
Expand Down Expand Up @@ -235,18 +236,18 @@
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppApp.targets'))" />
</Target>
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="$(SolutionDir)packages\Microsoft.ReactNative.0.63.2\build\native\Microsoft.ReactNative.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.ReactNative.0.63.2\build\native\Microsoft.ReactNative.targets')" />
<Import Project="$(SolutionDir)packages\Microsoft.ReactNative.Cxx.0.63.2\build\native\Microsoft.ReactNative.Cxx.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.ReactNative.Cxx.0.63.2\build\native\Microsoft.ReactNative.Cxx.targets')" />
<Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.targets')" />
<Import Project="$(SolutionDir)packages\Microsoft.ReactNative.1000.0.0\build\native\Microsoft.ReactNative.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.ReactNative.1000.0.0\build\native\Microsoft.ReactNative.targets')" />
<Import Project="$(SolutionDir)packages\Microsoft.ReactNative.Cxx.1000.0.0\build\native\Microsoft.ReactNative.Cxx.targets" Condition="Exists('$(SolutionDir)packages\Microsoft.ReactNative.Cxx.1000.0.0\build\native\Microsoft.ReactNative.Cxx.targets')" />
<Import Project="$(SolutionDir)packages\nlohmann.json.3.9.1\build\native\nlohmann.json.targets" Condition="Exists('$(SolutionDir)packages\nlohmann.json.3.9.1\build\native\nlohmann.json.targets')" />
<Import Project="$(SolutionDir)packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets" Condition="Exists('$(SolutionDir)packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.200729.8\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.props'))" />
<Error Condition="!Exists('$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.targets'))" />
<Error Condition="!Exists('$(SolutionDir)packages\nlohmann.json.3.9.1\build\native\nlohmann.json.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)packages\nlohmann.json.3.9.1\build\native\nlohmann.json.targets'))" />
</Target>
</Project>
6 changes: 4 additions & 2 deletions windows/ReactTestApp/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.UI.Xaml" version="2.4.3" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.200729.8" targetFramework="native" />
<package id="Microsoft.ReactNative" version="1000.0.0" targetFramework="native" />
<package id="Microsoft.ReactNative.Cxx" version="1000.0.0" targetFramework="native" />
<package id="Microsoft.UI.Xaml" version="2.5.0" targetFramework="native" />
<package id="Microsoft.Windows.CppWinRT" version="2.0.210312.4" targetFramework="native" />
<package id="nlohmann.json" version="3.9.1" targetFramework="native" />
</packages>
93 changes: 78 additions & 15 deletions windows/test-app.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ function getVersionNumber(version) {
/**
* Generates Visual Studio solution.
* @param {string} destPath Destination path.
* @param {boolean} [noAutolink] Skip autolinking.
* @param {{ noAutolink: boolean; useNuGet: boolean; }} params
* @returns {string | undefined} An error message; `undefined` otherwise.
*/
function generateSolution(destPath, noAutolink) {
function generateSolution(destPath, { noAutolink, useNuGet }) {
if (!destPath) {
throw "Missing or invalid destination path";
}
Expand Down Expand Up @@ -295,13 +295,23 @@ function generateSolution(destPath, noAutolink) {
const rnWindowsVersion = getPackageVersion(rnWindowsPath);

const projectFilesReplacements = {
...(useNuGet
? {
"<UseExperimentalNuget>false</UseExperimentalNuget>":
"<UseExperimentalNuget>true</UseExperimentalNuget>",
}
: {
'<package id="Microsoft.ReactNative" version="1000.0.0" targetFramework="native" />':
"",
'<package id="Microsoft.ReactNative.Cxx" version="1000.0.0" targetFramework="native" />':
"",
}),
"1000\\.0\\.0": rnWindowsVersion,
"REACT_NATIVE_VERSION=10000000;": `REACT_NATIVE_VERSION=${getVersionNumber(
rnWindowsVersion
)};`,
"\\$\\(BundleDirContentPaths\\)": bundleDirContent,
"\\$\\(BundleFileContentPaths\\)": bundleFileContent,
"packages\\\\Microsoft\\.ReactNative\\.0\\.63\\.2\\\\build\\\\native\\\\Microsoft\\.ReactNative\\.targets": `packages\\Microsoft.ReactNative.${rnWindowsVersion}\\build\\native\\Microsoft.ReactNative.targets`,
"packages\\\\Microsoft\\.ReactNative\\.Cxx\\.0\\.63\\.2\\\\build\\\\native\\\\Microsoft\\.ReactNative\\.Cxx\\.targets": `packages\\Microsoft.ReactNative.Cxx.${rnWindowsVersion}\\build\\native\\Microsoft.ReactNative.Cxx.targets`,
};

const copyTasks = [
Expand Down Expand Up @@ -377,10 +387,10 @@ function generateSolution(destPath, noAutolink) {
const solutionTask = fs.writeFile(
path.join(destPath, `${appName}.sln`),
mustache
.render(
fs.readFileSync(solutionTemplatePath, { encoding: "utf8" }),
templateView
)
.render(fs.readFileSync(solutionTemplatePath, { encoding: "utf8" }), {
...templateView,
useExperimentalNuget: useNuGet,
})
// The current version of this template (v0.63.18) assumes that
// `react-native-windows` is always installed in
// `..\node_modules\react-native-windows`.
Expand All @@ -406,6 +416,50 @@ function generateSolution(destPath, noAutolink) {
}
}
);
if (useNuGet) {
const nugetConfigPath =
findNearest(
// In 0.64, the template was moved into `react-native-windows`
path.join(
nodeModulesDir,
"react-native-windows",
"template",
"shared-app",
"proj",
"NuGet.Config"
)
) ||
findNearest(
// In 0.63, the template is in `@react-native-windows/cli`
path.join(
nodeModulesDir,
"@react-native-windows",
"cli",
"templates",
"shared",
"proj",
"NuGet.Config"
)
);
if (nugetConfigPath) {
fs.writeFile(
path.join(destPath, "NuGet.Config"),
mustache.render(
fs.readFileSync(nugetConfigPath, { encoding: "utf8" }),
{}
),
{
encoding: "utf8",
mode: 0o644,
},
(error) => {
if (error) {
throw error;
}
}
);
}
}
if (!noAutolink) {
Promise.all([...copyTasks, solutionTask]).then(() => {
const { spawn } = require("child_process");
Expand Down Expand Up @@ -443,23 +497,32 @@ if (require.main === module) {
"$0 [options]",
"Generate a Visual Studio solution for React Test App",
{
projectDirectory: {
"project-directory": {
alias: "p",
type: "string",
description: "Directory where solution will be created",
default: "windows",
},
noAutolink: {
"no-autolink": {
type: "boolean",
description: "Skip autolinking",
default: false,
},
"use-nuget": {
type: "boolean",
description: "Use NuGet packages (experimental)",
default: false,
},
},
({ projectDirectory, noAutolink }) => {
const error = generateSolution(
path.resolve(projectDirectory),
noAutolink
);
({
"project-directory": projectDirectory,
"no-autolink": noAutolink,
"use-nuget": useNuGet,
}) => {
const error = generateSolution(path.resolve(projectDirectory), {
noAutolink,
useNuGet,
});
if (error) {
console.error(error);
process.exit(1);
Expand Down
Loading

0 comments on commit 9a2a340

Please sign in to comment.