Skip to content

Commit

Permalink
fix(windows)!: Fix autolinking and remove legacy projects (#521)
Browse files Browse the repository at this point in the history
* Updates the module project with a newer template which will be
  detected by autolinking (RNW >= 0.63)
* Fixes react-native.config to properly identify the windows example project
* Removes the legacy C# project, which only confuses autolinking
* Updates docs around windows autolinking support

BREAKING CHANGE: Drop support for react-native-windows 0.61 and lower. Update to RNW 0.62 or higher
  • Loading branch information
jonthysell committed Nov 16, 2021
1 parent dafc674 commit 45628d8
Show file tree
Hide file tree
Showing 28 changed files with 356 additions and 1,402 deletions.
23 changes: 7 additions & 16 deletions README.md
Expand Up @@ -61,12 +61,12 @@ Linking the package manually is not required anymore with [Autolinking](https://

- **Windows Platform:**

Autolinking status is unknown on Windows. If you need to manually link, see the [Manual linking steps for Windows](#manual-linking-windows) below.
Autolinking works on RNW >= 0.63. If you need to manually link, see the [Manual linking steps for Windows](#manual-linking-windows) below.

<details id='manual-linking-windows'>
<summary>Manually link the library on Windows</summary>

#### Link C++ implementation
#### Link to your C++ app (RNW >= 0.62)
* Open the solution in Visual Studio for your Windows apps
* Right click in the Explorer and click Add > Existing Project...
* Navigate to `./<app-name>/node_modules/@react-native-community/netinfo/windows/RNCNetInfoCPP/` and add `RNCNetInfoCPP.vcxproj`
Expand All @@ -75,23 +75,14 @@ Linking the package manually is not required anymore with [Autolinking](https://
* Open `pch.h`, add `#include "winrt/ReactNativeNetInfo.h"`
* Open `App.cpp`, add `PackageProviders().Append(winrt::ReactNativeNetInfo::ReactPackageProvider());` before `InitializeComponent();`

#### Link C# implementation
#### Link C# to your C# app (RNW >= 0.62)
* Open the solution in Visual Studio for your Windows apps
* Right click in the Explorer and click Add > Existing Project...
* Navigate to `./<app-name>/node_modules/@react-native-community/netinfo/windows/RNCNetInfo/` and add `RNCNetInfo.csproj`
* Navigate to `./<app-name>/node_modules/@react-native-community/netinfo/windows/RNCNetInfoCPP/` and add `RNCNetInfoCPP.vcxproj`
* This time right click on your React Native Windows app under your solutions directory and click Add > Reference...
* Check the `RNCNetInfo` you just added and press ok
* Open up `MainReactNativeHost.cs` for your app and edit the file like so:

```diff
+ using ReactNativeCommunity.NetInfo;
......
protected override List<IReactPackage> Packages => new List<IReactPackage>
{
new MainReactPackage(),
+ new RNCNetInfoPackage(),
};
```
* Check the `RNCNetInfoCPP` you just added and press ok
* Open up `App.xaml.cs` for your app and add `using ReactNativeNetInfo;` to the top.
* Open up `App.xaml.cs` for your app and add `PackageProviders.Add(new ReactNativeNetInfo.ReactPackageProvider());` before `InitializeComponent();`

</details>

Expand Down
1 change: 0 additions & 1 deletion example/windows/NetInfoExample.sln
Expand Up @@ -38,7 +38,6 @@ EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9
..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{37e37094-01b3-44a5-aab7-f0379b1ce8fa}*SharedItemsImports = 4
..\..\node_modules\react-native-windows\Mso\Mso.vcxitems*{84e05bfa-cbaf-4f0d-bfb6-4ce85742a57e}*SharedItemsImports = 9
..\..\node_modules\react-native-windows\Chakra\Chakra.vcxitems*{c38970c0-5fbf-4d69-90d8-cbac225ae895}*SharedItemsImports = 9
..\..\node_modules\react-native-windows\Microsoft.ReactNative.Cxx\Microsoft.ReactNative.Cxx.vcxitems*{da8b35b3-da00-4b02-bde6-6a397b3fd46b}*SharedItemsImports = 9
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -84,7 +84,7 @@
"react-native-codegen": "^0.0.8",
"react-native-macos": "0.60.0-microsoft.50",
"react-native-web": "^0.17.5",
"react-native-windows": "0.65.6",
"react-native-windows": "0.65.8",
"react-test-renderer": "17.0.2",
"rimraf": "^2.6.3",
"semantic-release": "^17.4.6",
Expand Down
9 changes: 8 additions & 1 deletion react-native.config.js
Expand Up @@ -25,7 +25,14 @@ let config = {
},
android:{
sourceDir: 'example/android',
}
},
windows:{
sourceDir: 'example\\windows',
solutionFile: 'NetInfoExample.sln',
project: {
projectFile: 'NetInfoExample\\NetInfoExample.vcxproj',
},
},
},
}
if (process.argv.includes(macSwitch)) {
Expand Down

0 comments on commit 45628d8

Please sign in to comment.