See ../README.md for details of this sample.
See ../cppwinrt/ for a C++/WinRT version of this sample.
Note: Don't build your own projects directly out of this sample. When you publish a native module (as source), you'll want to create a new project with the correct metadata. This will also make sure that you're using unique identifiers in your project files to avoid conflicts with other native modules.
See ../README.md#Setup.
See ../README.md#Run.
To upgrade this sample to the latest version of RNW:
- Open a command prompt and navigate to this folder.
- Delete the
windows
folder:rd /s /q windows
- Upgrade dev dependencies to the versions of
react
andreact-native
needed byreact-native-windows@latest
:- Option A: Use the
UpgradeSmokeTest.ps1
helper script (Recommended on Windows Powershell):..\..\..\.github\scripts\UpgradeSmokeTest.ps1 latest
- Option B: Update the package.json by hand:
- Look up the version of
react
required byreact-native-windows@latest
:npm info react-native-windows@latest devDependencies.react
- Upgrade
react
to that version:yarn upgrade react@VERSIONFROMLASTSTEP
- Look up the version of
react-native
required byreact-native-windows@latest
:npm info react-native-windows@latest devDependencies.react-native
- Upgrade
react-native
to that version:yarn upgrade react-native@VERSIONFROMLASTSTEP
- Upgrade
react-native-windows
to the latest version:yarn upgrade react-native-windows@latest
- Look up the version of
- Option A: Use the
- Re-run the RNW CLI:
npx @react-native-community/cli@latest init-windows --template old/uwp-cs-lib --overwrite
- Restore these original native files (representing the native module samples):
git restore windows\NativeModuleSample\AsyncMethodExamples.cs git restore windows\NativeModuleSample\DataMarshallingExamples.cs git restore windows\NativeModuleSample\FancyMath.cs
- Remove these new native files:
del windows\NativeModuleSample\ReactNativeModule.cs
- Referring to a diff of the modified files, make the following updates:
- For
windows\NativeModuleSample\NativeModuleSample.csproj
:- Restore the
<Compile>
entries for the files restored in Step 5:+ <Compile Include="AsyncMethodExamples.cs" /> + <Compile Include="DataMarshallingExamples.cs" /> + <Compile Include="FancyMath.cs" />
- Remove the
<Compile>
entries for the files removed in Step 6:- <Compile Include="ReactNativeModule.cs" />
- Check if the
<ProjectGuid>
property at the top of the file has been updated. If so, take note of the new Guid (for later) and restore the original Guid.
- Restore the
- For
windows\NativeModuleSample\NativeModulesSample.sln
:- If the project guid was changed in Step 7.1.3 above, you'll want to restore the original Guid here too. The easiest way to do this is to just do a find-replace on the new Guid with the (uppercased) old one.
- For
ReactPackageProvider.cs
:- Restore the copyright notice at the top of the file:
+ // Copyright (c) Microsoft Corporation. All rights reserved. + // Licensed under the MIT License. +
- Restore the copyright notice at the top of the file:
- For
- Verify the updated sample builds:
npx @react-native-community/cli@latest run-windows --no-deploy --no-launch --no-packager --no-autolink --proj "NativeModuleSample\NativeModuleSample.csproj"
- Update the main readme with the new major version at the top.