Skip to content

Commit 131eea6

Browse files
authored
Enable PackageReference support if available (#232)
This PR checks if the version of RNW is >= 0.68.0, then switches to using `PackageReference` for NuGet dependencies instead of using the legacy `packages.config`. This PR also updates the GitHub Action workflow to reduce copy/pasting and expand the test matrix of RNW versions tested. Closes #230 Closes #231
1 parent c7a890b commit 131eea6

File tree

4 files changed

+42
-63
lines changed

4 files changed

+42
-63
lines changed

.github/workflows/SetUpAppForNuget.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ $AppName = Split-Path $PWD -Leaf
1010
Write-Host App name = $AppName
1111
$ns = "http://schemas.microsoft.com/developer/msbuild/2003"
1212

13-
[xml]$packagesConfig = Get-Content .\windows\$AppName\packages.config
14-
($packagesConfig.packages.package | Where-Object id -EQ 'Microsoft.UI.Xaml').version = $WinUIVersion.ToString()
15-
$packagesConfig.Save("$PWD\windows\$AppName\packages.config")
13+
if (Test-Path .\windows\$AppName\packages.config) {
14+
[xml]$packagesConfig = Get-Content .\windows\$AppName\packages.config
15+
($packagesConfig.packages.package | Where-Object id -EQ 'Microsoft.UI.Xaml').version = $WinUIVersion.ToString()
16+
$packagesConfig.Save("$PWD\windows\$AppName\packages.config")
17+
}
1618

1719
[xml]$EF = Get-Content .\windows\ExperimentalFeatures.props
1820
$node = $EF.Project.PropertyGroup.WinUI2xVersion

.github/workflows/main.yml

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ jobs:
6262

6363
testcli:
6464
runs-on: windows-2019
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
rnwSource: ['Source', 'NuGet'] # test building with both RNW source and RNW NuGet
69+
rnwVersion: ['^0.64', '^0.67', '^0.69'] # test key versions (min, partners)
6570
steps:
6671
- uses: actions/checkout@v2
6772
- name: yarn install
@@ -74,11 +79,11 @@ jobs:
7479
run: yarn link
7580
working-directory: package
7681

77-
- name: create 0.64 app
78-
run: npx react-native init testrnx --template react-native@^0.64
82+
- name: create ${{ matrix.rnwVersion }} app
83+
run: npx react-native init testrnx --template react-native@${{ matrix.rnwVersion }}
7984

80-
- name: add Windows
81-
run: npx react-native-windows-init --overwrite
85+
- name: add Windows (RNW via ${{ matrix.rnwSource }})
86+
run: npx react-native-windows-init --overwrite ${{ matrix.rnwSource == 'NuGet' && '--experimentalNuGetDependency true' || '' }}
8287
working-directory: testrnx
8388

8489
- name: link react-native-xaml
@@ -94,49 +99,7 @@ jobs:
9499
working-directory: testrnx
95100

96101
- name: update WinUI package version
97-
run: ..\.github\workflows\SetUpAppForNuget.ps1
98-
working-directory: testrnx
99-
100-
- name: build app
101-
run: npx react-native run-windows --no-launch --no-deploy --no-packager --logging
102-
working-directory: testrnx
103-
104-
105-
testcliNuGet:
106-
runs-on: windows-2019
107-
steps:
108-
- uses: actions/checkout@v2
109-
- name: yarn install
110-
run: yarn install
111-
112-
- name: build TS
113-
run: yarn build
114-
115-
- name: yarn link
116-
run: yarn link
117-
working-directory: package
118-
119-
- name: create 0.64 app
120-
run: npx react-native init testrnx --template react-native@^0.64
121-
122-
- name: add Windows
123-
run: npx react-native-windows-init --overwrite --experimentalNuGetDependency true
124-
working-directory: testrnx
125-
126-
- name: link react-native-xaml
127-
run: yarn link react-native-xaml
128-
working-directory: testrnx
129-
130-
- name: add react-native-xaml
131-
run: yarn add react-native-xaml
132-
working-directory: testrnx
133-
134-
- name: autolink
135-
run: npx react-native autolink-windows --logging
136-
working-directory: testrnx
137-
138-
- name: update WinUI package version and mark for NuGet package consumption
139-
run: ..\.github\workflows\SetUpAppForNuget.ps1 -UseNuGet
102+
run: ..\.github\workflows\SetUpAppForNuget.ps1 ${{ matrix.rnwSource == 'NuGet' && '-UseNuGet' || '' }}
140103
working-directory: testrnx
141104

142105
- name: build app
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Enable PackageReference support if available",
4+
"packageName": "react-native-xaml",
5+
"email": "jthysell@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

package/windows/ReactNativeXaml/ReactNativeXaml.vcxproj

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="16.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(SolutionDir)\ExperimentalFeatures.props" Condition="Exists('$(SolutionDir)\ExperimentalFeatures.props')" />
4+
<PropertyGroup Label="ReactNativeWindowsProps">
5+
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
6+
</PropertyGroup>
7+
<ImportGroup Label="ReactNativeWindowsPropertySheets">
8+
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\external\Microsoft.ReactNative.Uwp.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" />
9+
</ImportGroup>
10+
<PropertyGroup>
11+
<RnwUsesPackageReference Condition="$(RnwUsesPackageReference)=='' And $(ReactNativeWindowsVersion)!='' And $([MSBuild]::VersionGreaterThanOrEquals('$(ReactNativeWindowsVersion)', '0.68.0'))">true</RnwUsesPackageReference>
12+
</PropertyGroup>
413
<PropertyGroup>
5-
<CppWinRTVersion Condition="'$(CppWinRTVersion)'==''">2.0.210309.3</CppWinRTVersion>
14+
<CppWinRTVersion Condition="'$(CppWinRTVersion)'=='' Or $([MSBuild]::VersionLessThan('$(CppWinRTVersion)', '2.0.210309.3'))">2.0.210309.3</CppWinRTVersion>
615
</PropertyGroup>
7-
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props')" />
16+
<Import Project="$(SolutionDir)\packages\$(WinUIPackageProps)" Condition="$(RnwUsesPackageReference)!='true' And '$(OverrideWinUIPackage)'!='true' And '$(WinUIPackageProps)'!='' And Exists('$(SolutionDir)\packages\$(WinUIPackageProps)')" />
17+
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props" Condition="$(RnwUsesPackageReference)!='true' And Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props')" />
818
<PropertyGroup Label="Globals">
919
<CppWinRTOptimized>true</CppWinRTOptimized>
1020
<CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge>
@@ -21,9 +31,6 @@
2131
<WindowsTargetPlatformMinVersion>10.0.16299.0</WindowsTargetPlatformMinVersion>
2232
</PropertyGroup>
2333
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
24-
<PropertyGroup Label="ReactNativeWindowsProps">
25-
<ReactNativeWindowsDir Condition="'$(ReactNativeWindowsDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(SolutionDir), 'node_modules\react-native-windows\package.json'))\node_modules\react-native-windows\</ReactNativeWindowsDir>
26-
</PropertyGroup>
2734
<ItemGroup Label="ProjectConfigurations">
2835
<ProjectConfiguration Include="Debug|ARM">
2936
<Configuration>Debug</Configuration>
@@ -81,10 +88,6 @@
8188
<ImportGroup Label="PropertySheets">
8289
<Import Project="PropertySheet.props" />
8390
</ImportGroup>
84-
<ImportGroup Label="ReactNativeWindowsPropertySheets">
85-
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\external\Microsoft.ReactNative.Uwp.CppLib.props" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" />
86-
<Import Project="$(SolutionDir)\packages\$(WinUIPackageProps)" Condition="'$(WinUIPackageProps)'!='' And Exists('$(SolutionDir)\packages\$(WinUIPackageProps)')" />
87-
</ImportGroup>
8891
<PropertyGroup Label="UserMacros" />
8992
<ItemDefinitionGroup>
9093
<ClCompile>
@@ -235,6 +238,10 @@
235238
</ItemGroup>
236239
<Import Project="$(SolutionDir)\ReactNativeXaml.Imports.props" Condition="Exists('$(SolutionDir)\ReactNativeXaml.Imports.props')" />
237240
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
241+
<ItemGroup Condition="$(RnwUsesPackageReference)=='true'">
242+
<PackageReference Include="CDebug" Version="0.0.3" />
243+
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="$(CppWinRTVersion)" PrivateAssets="all" />
244+
</ItemGroup>
238245
<ImportGroup Label="ReactNativeWindowsTargets">
239246
<Import Project="$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets" Condition="Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" />
240247
</ImportGroup>
@@ -245,21 +252,21 @@
245252
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.props'))" />
246253
<Error Condition="!Exists('$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(ReactNativeWindowsDir)\PropertySheets\External\Microsoft.ReactNative.Uwp.CppLib.targets'))" />
247254
</Target>
248-
<ImportGroup Label="ExtensionTargets">
255+
<ImportGroup Label="ExtensionTargets" Condition="$(RnwUsesPackageReference)!='true'">
249256
<Import Project="$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets')" />
250257
<Import Project="$(SolutionDir)\packages\CDebug.0.0.3\build\CDebug.targets" Condition="Exists('$(SolutionDir)\packages\CDebug.0.0.3\build\CDebug.targets')" />
251-
<Import Project="$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets" Condition="Exists('$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets')" />
258+
<Import Project="$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets" Condition="'$(OverrideWinUIPackage)'!='true' And Exists('$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets')" />
252259
<Import Project="$(SolutionDir)\packages\Microsoft.ReactNative.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.targets" Condition="'$(UseExperimentalNuget)'=='true' And Exists('$(SolutionDir)\packages\Microsoft.ReactNative.Cxx.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.Cxx.targets')" />
253260
<Import Project="$(SolutionDir)\packages\Microsoft.ReactNative.Cxx.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.Cxx.targets" Condition="'$(UseExperimentalNuget)'=='true' And Exists('$(SolutionDir)\packages\Microsoft.ReactNative.Cxx.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.Cxx.targets')" />
254261
</ImportGroup>
255-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
262+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" Condition="$(RnwUsesPackageReference)!='true'">
256263
<PropertyGroup>
257264
<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>
258265
</PropertyGroup>
259266
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.props'))" />
260267
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.$(CppWinRTVersion)\build\native\Microsoft.Windows.CppWinRT.targets'))" />
261268
<Error Condition="!Exists('$(SolutionDir)\packages\CDebug.0.0.3\build\CDebug.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\CDebug.0.0.3\build\CDebug.targets'))" />
262-
<Error Condition="!Exists('$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets'))" />
269+
<Error Condition="'$(OverrideWinUIPackage)'!='true' And !Exists('$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets'))" />
263270
<Error Condition="'$(UseExperimentalNuget)'=='true' And !Exists('$(SolutionDir)\packages\Microsoft.ReactNative.Cxx.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.Cxx.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ReactNative.Cxx.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.Cxx.targets'))" />
264271
<Error Condition="'$(UseExperimentalNuget)'=='true' And !Exists('$(SolutionDir)\packages\Microsoft.ReactNative.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ReactNative.$(ReactNativeWindowsVersion)\build\native\Microsoft.ReactNative.targets'))" />
265272
</Target>

0 commit comments

Comments
 (0)