Skip to content

Commit 1154dfe

Browse files
authored
[0.76] Update the cpp-lib template project to support importing either paper Uwp or fabric Composition prop/targets (#14024)
This PR backports #13945 to 0.76. ## Description This PR creates new "entry" prop/target imports for C++ libraries that depend on the `UseFabric` property to conditionally import either the old Uwp props/targets or the new Composition props/targets. ### Type of Change - New feature (non-breaking change which adds functionality) ### Why This helps enable module projects to support both paper and fabric with the same build files. Resolves #13928. ### What Added new imports, updated the `cpp-lib` template and existing sample to load them. ## Screenshots N/A ## Testing N/A ## Changelog Should this change be included in the release notes: yes Update the `cpp-lib` template project to support importing either paper Uwp or fabric Composition prop/targets
1 parent 3aa8532 commit 1154dfe

File tree

7 files changed

+60
-8
lines changed

7 files changed

+60
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "[0.76] Create hybrid CppLib props/targets",
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": "[0.76] Create hybrid CppLib props/targets",
4+
"packageName": "react-native-windows",
5+
"email": "jthysell@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/cli/src/commands/config/configUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export function isRnwDependencyProject(filePath: string): boolean {
118118
importProjectExists(
119119
projectContents,
120120
'Microsoft.ReactNative.Composition.CppLib.targets',
121+
) ||
122+
importProjectExists(
123+
projectContents,
124+
'Microsoft.ReactNative.CppLib.targets',
121125
)
122126
);
123127
}

packages/sample-custom-component/windows/SampleCustomComponent/SampleCustomComponent.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6666
</ImportGroup>
6767
<ImportGroup Label="ReactNativeWindowsPropertySheets">
68-
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props" />
68+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" />
6969
</ImportGroup>
7070
<ItemDefinitionGroup>
7171
<ClCompile>
@@ -137,13 +137,13 @@
137137
</ItemGroup>
138138
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
139139
<ImportGroup Label="ReactNativeWindowsTargets">
140-
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets')" />
140+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" />
141141
</ImportGroup>
142142
<Target Name="EnsureReactNativeWindowsTargets" BeforeTargets="PrepareForBuild">
143143
<PropertyGroup>
144144
<ErrorText>This project references targets in your node_modules\react-native-windows folder. The missing file is {0}.</ErrorText>
145145
</PropertyGroup>
146-
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props'))" />
147-
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets'))" />
146+
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props'))" />
147+
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets'))" />
148148
</Target>
149149
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (c) Microsoft Corporation.
4+
Licensed under the MIT License.
5+
6+
This file will be consumed by ALL C++ module projects (both inside
7+
and outside of this repo) that build on top of Microsoft.ReactNative.
8+
Do not make any changes here unless it applies to ALL such projects.
9+
-->
10+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
11+
<ImportGroup Condition="'$(UseFabric)' == 'true'">
12+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.ReactNative.Composition.CppLib.props" />
13+
</ImportGroup>
14+
<ImportGroup Condition="'$(UseFabric)' != 'true'">
15+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.ReactNative.Uwp.CppLib.props" />
16+
</ImportGroup>
17+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (c) Microsoft Corporation.
4+
Licensed under the MIT License.
5+
6+
This file will be consumed by ALL C++ module projects (both inside
7+
and outside of this repo) that build on top of Microsoft.ReactNative.
8+
Do not make any changes here unless it applies to ALL such projects.
9+
-->
10+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
11+
<ImportGroup Condition="'$(UseFabric)' == 'true'">
12+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.ReactNative.Composition.CppLib.targets" />
13+
</ImportGroup>
14+
<ImportGroup Condition="'$(UseFabric)' != 'true'">
15+
<Import Project="$(MSBuildThisFileDirectory)Microsoft.ReactNative.Uwp.CppLib.targets" />
16+
</ImportGroup>
17+
</Project>

vnext/templates/cpp-lib/windows/MyLib/MyLib.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6767
</ImportGroup>
6868
<ImportGroup Label="ReactNativeWindowsPropertySheets">
69-
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props" />
69+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" />
7070
</ImportGroup>
7171
<ItemDefinitionGroup>
7272
<ClCompile>
@@ -131,7 +131,7 @@
131131
</ItemGroup>
132132
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
133133
<ImportGroup Label="ReactNativeWindowsTargets">
134-
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets')" />
134+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" />
135135
</ImportGroup>
136136
<ItemGroup>
137137
{{#cppNugetPackages}}
@@ -142,7 +142,7 @@
142142
<PropertyGroup>
143143
<ErrorText>This project references targets in your node_modules\react-native-windows folder. The missing file is {0}.</ErrorText>
144144
</PropertyGroup>
145-
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.props'))" />
146-
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Composition.CppLib.targets'))" />
145+
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.props'))" />
146+
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.CppLib.targets'))" />
147147
</Target>
148148
</Project>

0 commit comments

Comments
 (0)