This post was most recently updated on November 2nd, 2022.2 min read.
This is something that comes up pretty often – when you’re building an application, or maybe a library you’re sharing as a NuGet package to your friends: You’ll need to share a dependency or two with your particular package, and you don’t want your end users having to reference those libraries, too.
Sounds easy, right? But alas, it’s not as simple as one would like :)
(Well, unless you’re happy running dotnet publish every time – that should work, but I want to have these files available right after dotnet build instead)
Table of Contents
Sounds easy, right? There’s a problem, though – you can’t just set “Copy Local” to “true” anymore. That’s simply not available for your dependencies.
And forget all of that <IncludeAssets> nonsense inside your PackageReferences – probably not going to help either.
At least I was getting a bit frustrated. Couldn’t find a way to include the DLLs without building some super questionable build conditions and/or scripts. Or, well, running dotnet publish all the time.
However, there’s another solution available!
The solution includes modifying your .csproj file (because of course it does!) – let’s see how:
Time needed: 5 minutes
How to copy referenced assemblies to the bin folder on build?
- Open your project file
Simple enough, just select “Edit Project File” by clicking your project using the right mouse button in the Solution Explorer.
- Add CopyLocalLockFileAssemblies to your .csproj file
Okay – so you need to add this to your <PropertyGroup>:
This will copy all of the NuGet dependencies to your output directory!
The documentation says this:
If you set this property to true, any NuGet package dependencies are copied to the output directory. That means you can use the output of dotnet build to run your plugin on any machine.
- Reload project and rebuild
After reloading and rebuilding you should be good!
And that’s it!
How did it go for you? Let me know in the comments section below!
- This was actually neatly documented at Clive’s Vade Mecum 2.0, here:
- node build throwing “error:0308010C:digital envelope routines::unsupported”? Let’s fix it! - September 19, 2023
- “This app can’t run on your PC” dialog when you’re building your app in Visual Studio - September 12, 2023
- How to “fix” Word removing tagged users from comments? - September 5, 2023