This essentially amounts to, "how do I clone a .NET project, make modifications, and use it rather than the published one?"
In NodeJS, we have npm link
, which lets you link a local package (module) in your node_modules/ directory, to your current project. So for example, instead of using Express in your package.json, you can
npm link
in Express repo to create a globally available local packagenpm link express
in your current project to use your local express, rather that the one you would get if you npm install
it.With .NET, the closest solution I have seen so far includes creating a local feed, but in my experimentation this doesn't seem to work. Other questions on stack overflow like how to use local packages in .net seem to offer solutions using RestoreSources, which is virtually undocumented across the entire web. When attempting to change RestoreSources to use a LocalPackages directory, it is not clear to me the local packages are being used or not (source in obj/ directory still seems to come from nuget package rather than local).
npm allows you to install and manage packages for use in both Node. js and ASP.NET Core applications.
Npm installs and tracks JavaScript dependencies. NuGet manages dependencies for . NET projects. Gradle manages dependencies and the build process for Java projects.
This can be all the more frustrating because npm link doesn't throw an error when this happens. Notice how the bottom line resolves to a folder where the dependency resides locally. To fix this, use node -v in each project and check the running version of node. Use nvm install x.x.x & nvm use x.x.x to match them up.
For anyone in the future wondering this, the correct answer is to use the local feed. My problem was that I had cached nuget packages which were being resolved during dotnet restore
.
The following command before restore solved my issues:
dotnet nuget locals all --clear
dotnet restore
Essentially, you need to have a nuget
config (NuGet.config) in your solution that sets up your local packages directory:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="LocalDev" value="./my-project/artifacts" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
Where artifacts/ directory contains all of the .nupkg
packages you want to use during restore. It is obviously also essential that you must make sure those packages are built/compiled before you dotnet restore
in your primary solution:
dotnet pack /p:Version=5.22.12 --configuration Release --force --output "%~dp0artifacts";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With