Add Conditional Macro to override NuGet Package Location for RNW Project Files
Proposal: Add Conditional Macro to override NuGet Package Location for RNW Project Files
Summary
Currently the RNW project files always look at the $(SolutionDir)\packages path for NuGet dependencies. The proposed change would add a custom macro that consumers can use to specify where the RNW project files should look for their NuGet dependencies. This macro should be a conditional macro, so that if it is not specified by the consumer it will fall back to the default $(SolutionDir)\packages path.
Motivation
Currently, consumers of RNW cannot modify the path that NuGet packages (using the repositoryPath key, for example) are pulled down to without causing RNW to fail to build. This is functionality that can be useful for repository maintenance, especially on larger projects.
More importantly for our scenario, it blocks integration of RNW into a codebase that has overwritten the path that NuGet packages are pulled down to. We have a set of shared native C++/WinRT projects that are critical for core functionality like user management across a family of applications, and until this support is added RNW is incompatible with using those projects and blocking development.
Open Questions
For context: this change was discussed on teams. We're wrapping up the investigation phase of this project now and want to move into implementation shortly, which we're targeting to start on 4/5 (April 5th, 2021). That being said, having the change were available sooner would always be preferable.
Here are the version of React, RN, and RNW that we're targeting: "dependencies": { "react": "16.13.1", "react-native": "0.63.4", "react-native-windows": "0.63.20" } But we're excited for 0.64 and are looking forward to moving to that when it becomes available, assuming we don't have any blockers.
Request makes sense. This has the possibility to break community modules, so any change we'd make for this we would have to replicate through all the community modules.
@asklar Just to clarify, can you elaborate on what you mean by "This has the possibility to break community modules"? I certainly agree that if someone does change their package path, community modules that haven't adopted this change would break. But assuming this is set up as a conditional macro that defaults to the existing behavior, nothing would break by default.
In that case, for the people who do choose to override their package path, that is an intentional action that they're taking which isn't easy to accidentally make. So it seems like it would be fairly reasonable for those teams to ensure their other dependencies can support making such a change, particularly because nobody using RNW currently is doing that given that RNW doesn't support that behavior right now.
@JunielKatarn - tagging you on this issue as you might find it interesting.
@willmayn Starting RNW 0.68, we are delivering support for the PackageReference mechanism already used by .NET/C#.
This means NuGet dependencies are no longer downloaded to a hard-coded local path ($(SolutionDir)packages), but directly consumed in the user's globalPackagesFolder.
Setting that variable in the NuGet.config allows setting an arbitrary packages path.
I don't think this is necessary anymore with PackageReference support.