Skip to content

Commit 9ce78de

Browse files
authored
Switch New Architecture templates to use prebuilt NuGets (#13338)
## Description This PR updates the `cpp-app` and `cpp-lib` new architecture templates to build against the pre-built `Microsoft.ReactNative` NuGet packages by default. ### Type of Change - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - This change requires a documentation update ### Why Building the `Microsoft.ReactNative` native code is very resource-intensive. Pre-building that code makes for much faster builds and greatly improved developer experience. This experience has been experimental and poorly support for Paper for some time now - for the new architecture projects we want using NuGets to be the primary experience from day one. Resolves #12639 ### What The `cpp-app` and `cpp-lib` new architecture templates now set up projects to consume the ("-Fabric" versions) of the pre-built `Microsoft.ReactNative` NuGet packages by default. The CI and PR builds have also been updated to make sure nugets for x64, x86, arm64 are built first and then consumed by the new project tests. To support working on RNW itself, the new projects made using "devMode" (i.e. by yarn linking with your local RNW repo) will still build against the source of that local RNW repo rather than the nugets. This PR also fixes the `--singleproc` flag for `run-windows`. Previously it didn't do anything on machines with high RAM, but now if you specify the flag it forces single processor builds as expected. ## Screenshots Building x64 Release Paper (build RNW from source): ![image](https://github.com/user-attachments/assets/d7a529b9-d313-4227-b236-f4781aa25855) Building x64 Release Fabric (use RNW Nugets): ![image](https://github.com/user-attachments/assets/bdb81df2-e111-4d61-a20a-302b3b6b1ecf) ## Testing Verified new projects build and run using the pre-built nugets. ## Changelog Should this change be included in the release notes: _yes_ Switch New Architecture templates to use prebuilt NuGets
1 parent 849d71f commit 9ce78de

21 files changed

+199
-25
lines changed

.ado/jobs/cli-init-windows.yml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ parameters:
88
- Continuous
99
- name: AgentPool
1010
type: object
11+
- name: buildNuGetOnly
12+
type: boolean
13+
default: false
1114
- name: buildMatrix
1215
type: object
1316
default:
@@ -18,31 +21,37 @@ parameters:
1821
configuration: Release
1922
platform: x64
2023
additionalRunArguments: --no-autolink
24+
useNuGet: true
2125
- Name: FabricX86Debug
2226
template: cpp-app
2327
configuration: Debug
2428
platform: x86
2529
additionalRunArguments: --no-autolink
30+
useNuGet: true
2631
- Name: FabricArm64Release
2732
template: cpp-app
2833
configuration: Release
2934
platform: ARM64
3035
additionalRunArguments: --no-autolink --no-deploy
36+
useNuGet: true
3137
- Name: FabricLibX64Release
3238
template: cpp-lib
3339
configuration: Release
3440
platform: x64
35-
additionalRunArguments:
41+
additionalRunArguments: --singleproc # --singleproc required to workaround issue #13599
42+
useNuGet: true
3643
- Name: FabricLibX86Debug
3744
template: cpp-lib
3845
configuration: Debug
3946
platform: x86
40-
additionalRunArguments:
47+
additionalRunArguments: --singleproc # --singleproc required to workaround issue #13599
48+
useNuGet: true
4149
- Name: FabricLibArm64Release
4250
template: cpp-lib
4351
configuration: Release
4452
platform: ARM64
45-
additionalRunArguments: --no-deploy
53+
additionalRunArguments: --no-deploy --singleproc # --singleproc required to workaround issue #13599
54+
useNuGet: true
4655
- Name: PaperX64ReleaseCpp
4756
template: old/uwp-cpp-app
4857
configuration: Release
@@ -108,67 +117,79 @@ parameters:
108117
configuration: Release
109118
platform: x64
110119
additionalRunArguments: --no-autolink
120+
useNuGet: true
111121
- BuildEnvironment: Continuous
112122
Matrix:
113123
- Name: FabricX64Debug
114124
template: cpp-app
115125
configuration: Debug
116126
platform: x64
117127
additionalRunArguments: --no-autolink
128+
useNuGet: true
118129
- Name: FabricX64Release
119130
template: cpp-app
120131
configuration: Release
121132
platform: x64
122133
additionalRunArguments: --no-autolink
134+
useNuGet: true
123135
- Name: FabricX86Debug
124136
template: cpp-app
125137
configuration: Debug
126138
platform: x86
127139
additionalRunArguments: --no-autolink
140+
useNuGet: true
128141
- Name: FabricX86Release
129142
template: cpp-app
130143
configuration: Release
131144
platform: x86
145+
useNuGet: true
132146
- Name: FabricArm64Debug
133147
template: cpp-app
134148
configuration: Debug
135149
platform: ARM64
136150
additionalRunArguments: --no-autolink --no-deploy
151+
useNuGet: true
137152
- Name: FabricArm64Release
138153
template: cpp-app
139154
configuration: Release
140155
platform: ARM64
141156
additionalRunArguments: --no-autolink --no-deploy
157+
useNuGet: true
142158
- Name: FabricLibX64Debug
143159
template: cpp-lib
144160
configuration: Debug
145161
platform: x64
146-
additionalRunArguments:
162+
additionalRunArguments: --singleproc # --singleproc required to workaround issue #13599
163+
useNuGet: true
147164
- Name: FabricLibX64Release
148165
template: cpp-lib
149166
configuration: Release
150167
platform: x64
151-
additionalRunArguments:
168+
additionalRunArguments: --singleproc # --singleproc required to workaround issue #13599
152169
- Name: FabricLibX86Debug
153170
template: cpp-lib
154171
configuration: Debug
155172
platform: x86
156-
additionalRunArguments:
173+
additionalRunArguments: --singleproc # --singleproc required to workaround issue #13599
174+
useNuGet: true
157175
- Name: FabricLibX86Release
158176
template: cpp-lib
159177
configuration: Release
160178
platform: x86
161-
additionalRunArguments:
179+
additionalRunArguments: --singleproc # --singleproc required to workaround issue #13599
180+
useNuGet: true
162181
- Name: FabricLibArm64Debug
163182
template: cpp-lib
164183
configuration: Debug
165184
platform: ARM64
166-
additionalRunArguments: --no-deploy
185+
additionalRunArguments: --no-deploy --singleproc # --singleproc required to workaround issue #13599
186+
useNuGet: true
167187
- Name: FabricLibArm64Release
168188
template: cpp-lib
169189
configuration: Release
170190
platform: ARM64
171-
additionalRunArguments: --no-deploy
191+
additionalRunArguments: --no-deploy --singleproc # --singleproc required to workaround issue #13599
192+
useNuGet: true
172193
- Name: PaperX64ReleaseCpp
173194
template: old/uwp-cpp-app
174195
configuration: Release
@@ -274,9 +295,14 @@ jobs:
274295
- ${{ each config in parameters.buildMatrix }}:
275296
- ${{ if eq(config.BuildEnvironment, parameters.buildEnvironment) }}:
276297
- ${{ each matrix in config.Matrix }}:
298+
- ${{ if eq(coalesce(matrix.useNuGet, false), parameters.buildNuGetOnly) }}:
277299
- job: CliInitWindows${{ matrix.Name }}
278300
displayName: Verify CliInitWindows ${{ matrix.Name }}
279301

302+
${{ if eq(matrix.useNuGet, true) }}:
303+
dependsOn:
304+
- UniversalBuild${{ matrix.platform }}ReleaseFabric
305+
280306
variables: [template: ../variables/windows.yml]
281307

282308
${{ if eq(matrix.lowResource, true) }}:
@@ -315,3 +341,4 @@ jobs:
315341
runWack: ${{ coalesce(matrix.runWack, false) }}
316342
buildEnvironment: ${{ parameters.buildEnvironment }}
317343
useChakra: ${{ coalesce(matrix.useChakra, false) }}
344+
useNuGet: ${{ coalesce(matrix.useNuGet, false) }}

.ado/jobs/universal.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,22 @@
3030
BuildConfiguration: Debug
3131
BuildPlatform: x64
3232
UseFabric: true
33+
- Name: X64ReleaseFabric
34+
BuildConfiguration: Release
35+
BuildPlatform: x64
36+
UseFabric: true
3337
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
3438
BuildConfiguration: Release
3539
BuildPlatform: x86
3640
UseFabric: true
41+
- Name: Arm64ReleaseFabric
42+
BuildConfiguration: Release
43+
BuildPlatform: ARM64
44+
UseFabric: true
3745
- BuildEnvironment: SecurePullRequest
3846
Matrix:
39-
- Name: X64DebugFabric
40-
BuildConfiguration: Debug
47+
- Name: X64ReleaseFabric
48+
BuildConfiguration: Release
4149
BuildPlatform: x64
4250
UseFabric: true
4351
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
@@ -75,10 +83,26 @@
7583
BuildConfiguration: Debug
7684
BuildPlatform: x64
7785
UseFabric: true
86+
- Name: X64ReleaseFabric
87+
BuildConfiguration: Release
88+
BuildPlatform: x64
89+
UseFabric: true
90+
- Name: X86DebugFabric
91+
BuildConfiguration: Debug
92+
BuildPlatform: x86
93+
UseFabric: true
7894
- Name: X86ReleaseFabric # Specifically built so binskim / tests get run on fabric
7995
BuildConfiguration: Release
8096
BuildPlatform: x86
8197
UseFabric: true
98+
- Name: Arm64DebugFabric
99+
BuildConfiguration: Debug
100+
BuildPlatform: ARM64
101+
UseFabric: true
102+
- Name: Arm64ReleaseFabric
103+
BuildConfiguration: Release
104+
BuildPlatform: ARM64
105+
UseFabric: true
82106

83107
jobs:
84108
- ${{ each config in parameters.buildMatrix }}:

.ado/stages.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ stages:
3434
parameters:
3535
buildEnvironment: ${{ parameters.buildEnvironment }}
3636
AgentPool: ${{ parameters.AgentPool }}
37+
38+
- template: jobs/cli-init-windows.yml
39+
parameters:
40+
buildEnvironment: ${{ parameters.buildEnvironment }}
41+
AgentPool: ${{ parameters.AgentPool }}
42+
buildNuGetOnly: true
3743

3844
- stage: IntegrationTests
3945
displayName: Tests 🧪
@@ -79,3 +85,4 @@ stages:
7985
parameters:
8086
buildEnvironment: ${{ parameters.buildEnvironment }}
8187
AgentPool: ${{ parameters.AgentPool }}
88+
buildNuGetOnly: false

.ado/templates/react-native-init-windows.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ parameters:
2222
- name: useChakra
2323
type: boolean
2424
default: false
25+
- name: useNuGet
26+
type: boolean
27+
default: false
2528
- name: runWack
2629
type: boolean
2730
default: false
@@ -41,6 +44,17 @@ steps:
4144
parameters:
4245
buildEnvironment: ${{ parameters.buildEnvironment }}
4346

47+
- ${{ if eq(parameters.useNuGet, true) }}:
48+
- template: prep-and-pack-nuget.yml
49+
parameters:
50+
artifactName: ReactWindowsFabric
51+
npmVersion: $(npmVersion)-Fabric
52+
packMicrosoftReactNative: true
53+
packMicrosoftReactNativeCxx: true
54+
slices:
55+
- platform: ${{ parameters.platform }}
56+
configuration: Release
57+
4458
- ${{ if endsWith(parameters.template, '-app') }}:
4559
- script: | # Change version of @react-native-community/template from 'nightly' to '$(reactNativeDevDependency)' - Windows #13446
4660
npx --yes @react-native-community/cli@next init testcli --template @react-native-community/template@nightly
@@ -171,6 +185,15 @@ steps:
171185
${{ else }}:
172186
workingDirectory: $(Agent.BuildDirectory)\testcli
173187

188+
- ${{ if eq(parameters.useNuGet, true) }}:
189+
- powershell: |
190+
nuget.exe sources add -name TestFeed -source $(System.DefaultWorkingDirectory)\NugetTestFeed
191+
nuget.exe sources remove -name react-native
192+
nuget.exe sources remove -name Nuget.org
193+
nuget.exe sources add -name Nuget.org -source https://api.nuget.org/v3/index.json
194+
displayName: Add local NuGet test feed
195+
workingDirectory: $(Agent.BuildDirectory)\testcli
196+
174197
- template: ../templates/run-windows-with-certificates.yml
175198
parameters:
176199
buildEnvironment: ${{ parameters.BuildEnvironment }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix run-windows --singleproc to override high memory",
4+
"packageName": "@react-native-windows/cli",
5+
"email": "jthysell@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Switch New Architecture templates to use prebuilt NuGets",
4+
"packageName": "react-native-windows",
5+
"email": "jthysell@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/cli/src/utils/msbuildtools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class MSBuildTools {
119119
// doesn't lead to dramatic performance gains (See #4739). Only enable
120120
// parallel builds on machines with >16GB of memory to avoid OOM errors
121121
const highMemory = totalmem() > 16 * 1024 * 1024 * 1024;
122-
const enableParallelBuilds = singleproc === false || highMemory;
122+
const enableParallelBuilds = singleproc !== true && highMemory;
123123

124124
if (enableParallelBuilds) {
125125
args.push('/maxCpuCount');

vnext/PropertySheets/External/Microsoft.ReactNative.Composition.Package.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
<Import Project="$(MSBuildThisFileDirectory)Microsoft.ReactNative.Common.props" />
1212
<!-- Fixes NuGet restore issues: -->
1313
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\NuGet.CSharp.props" />
14+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\WinUI.props" />
1415
</Project>

vnext/PropertySheets/External/Microsoft.ReactNative.Composition.Package.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
<!-- Needed for ucrtbased.dll when running a debug build. -->
1515
<SDKReference Include="Microsoft.VCLibs, Version=14.0" Condition="'$(Configuration)' == 'Debug'" />
1616
</ItemGroup>
17+
18+
<ItemGroup Condition="'$(UseExperimentalNuget)' == 'true'">
19+
<PackageReference Include="$(WinUIPackageName)" Version="$(WinUIPackageVersion)" Condition="'$(OverrideWinUIPackage)'!='true'" />
20+
</ItemGroup>
1721

1822
</Project>

vnext/PropertySheets/External/Microsoft.ReactNative.Cpp.PackageReferences.props

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
-->
66
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
77
<!-- Only include Microsoft.ReactNative.* NuGet packages that C++ (app and lib) projects need when using UseExperimentalNuget. -->
8-
<ItemGroup>
9-
<PackageReference Include="Microsoft.ReactNative" Version="$(ReactNativeWindowsVersion)" />
10-
<PackageReference Include="Microsoft.ReactNative.Cxx" Version="$(ReactNativeWindowsVersion)" />
11-
</ItemGroup>
8+
<Choose>
9+
<When Condition="'$(UseFabric)' == 'true'">
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.ReactNative" Version="$(ReactNativeWindowsVersion)-Fabric" />
12+
<PackageReference Include="Microsoft.ReactNative.Cxx" Version="$(ReactNativeWindowsVersion)-Fabric" />
13+
</ItemGroup>
14+
</When>
15+
<Otherwise>
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.ReactNative" Version="$(ReactNativeWindowsVersion)" />
18+
<PackageReference Include="Microsoft.ReactNative.Cxx" Version="$(ReactNativeWindowsVersion)" />
19+
</ItemGroup>
20+
</Otherwise>
21+
</Choose>
1222
</Project>

vnext/Scripts/Microsoft.ReactNative.VersionCheck.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
<PropertyGroup>
6868
<_ReactNativeWindowsVersionCheckNugetVersion>$$nuGetPackageVersion$$</_ReactNativeWindowsVersionCheckNugetVersion>
69+
<!-- Strip out the -Fabric qualifier from the version string if present -->
70+
<_ReactNativeWindowsVersionCheckNugetVersion>$(_ReactNativeWindowsVersionCheckNugetVersion.Replace('-Fabric', ''))</_ReactNativeWindowsVersionCheckNugetVersion>
6971
</PropertyGroup>
7072

7173
<!-- Validate package.json file -->

vnext/templates/cpp-app/NuGet_Config

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<clear />
5+
{{#addReactNativePublicAdoFeed}}
6+
<add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />
7+
{{/addReactNativePublicAdoFeed}}
8+
<add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
9+
</packageSources>
10+
<disabledPackageSources>
11+
<clear />
12+
</disabledPackageSources>
13+
</configuration>

vnext/templates/cpp-app/template.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function preInstall(config = {}, options = {}) {}
2121

2222
async function getFileMappings(config = {}, options = {}) {
2323
const projectRoot = config?.root ?? process.cwd();
24-
const {rnwPath, rnwVersion, devMode} = templateUtils.getRnwInfo(config, options);
24+
const {rnwPath, rnwVersion, devMode, isCanary} = templateUtils.getRnwInfo(config, options);
2525

2626
const projectName =
2727
config?.project?.windows?.project?.projectName ?? options?.name ?? 'MyApp';
@@ -66,6 +66,9 @@ async function getFileMappings(config = {}, options = {}) {
6666

6767
devMode,
6868

69+
useNuGets: !devMode, // default is to use published NuGets except in devMode, change to true here if you want to test devMode and nugets simultaneously
70+
addReactNativePublicAdoFeed: isCanary,
71+
6972
cppNugetPackages,
7073
};
7174

vnext/templates/cpp-app/windows/ExperimentalFeatures.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup Label="Microsoft.ReactNative Experimental Features">
55
<UseFabric>true</UseFabric>
66
<UseWinUI3>true</UseWinUI3>
7+
<UseExperimentalNuget>{{useNuGets}}</UseExperimentalNuget>
78

89
<ReactExperimentalFeaturesSet>true</ReactExperimentalFeaturesSet>
910
</PropertyGroup>

0 commit comments

Comments
 (0)