How do I get .NET Core projects to copy NuGet references to the build output?
You can add this to a <PropertyGroup>
inside your csproj file to enforce copying NuGet assemblies to the build output:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
However, note that the build output (bin/Release/netcoreapp*/*
) is not supposed to be portable and distributable, the output of dotnet publish
is. But in your case, copying the assemblies to the build output is probably very useful for testing purposes. But note that you could also use the DependencyContext
api to resolve the DLLs and their locations that are part of the application's dependency graph instead of enumerating a local directory.
How to configure a .NET Core project to copy a specified NuGet reference to the build output?
Assuming you're using Visual Studio...
Project->Properties->Build Events
"Put this in the Post-build event command line:" box
copy "$(SolutionDir)assembly.dll" "$(TargetDir)"
Or add this to your project file:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy "$(SolutionDir)assembly.dll" "$(TargetDir)"" />
</Target>
Is there a way to copy nuget package references from one solution to another in .net-core?
You could just copy the PackageReference nodes you need to the new project. Source:
https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
<ItemGroup>
<!-- ... -->
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0" />
<!-- ... -->
</ItemGroup>
Some interesting reads: What are package references and how will they help me optimise the way I deal with Nuget packages and Migrate from packages.config to PackageReference
Copy NuGet contentFiles transitively to referenced project
If you are in control of the NuGet package
You can add additional build targets in which you are able to specify that the content files should be copied.
Add build/MyNuGetPackage.targets
to the NuGet package:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<!-- For all files in /contentFiles -->
<Content Include="$(MSBuildThisFileDirectory)..\contentFiles\**\*.*">
<!-- Copy to output directory on build -->
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
This will copy all content files of this package into the output folder, including cases where this package is transitively referenced.
.Net Core - Building to release does not copy NUGET dependencies
It's the difference between building (for testing) and publishing (for deployment to production). dotnet build
will build your application for local testing and usage. It will assume that nuget dependencies are present on the machine. If you want to build for deployment, use dotnet publish
instead:
dotnet publish -c Release
Then look into the ./bin/Release/netcoreapp2.0/publish
directory. It should contain all your dependencies too.
See https://docs.microsoft.com/en-us/dotnet/core/deploying/deploy-with-cli for more details.
Related Topics
C# SQL Server - Passing a List to a Stored Procedure
Is Using a 'Goto' Statement Bad
At the End of an Async Method, Should I Return or Await
Oledbcommand Parameters Order and Priority
Why Can't I Inherit Static Classes
Reading Datetime Value from Excel Sheet
A Field Initializer Cannot Reference the Non-Static Field, Method, or Property
Failed to Serialize the Response in Web API with JSON
How to Pass Ienumerable List to Controller in MVC Including Checkbox State
An Implementation of the Fast Fourier Transform (Fft) in C#
Solution for Overloaded Operator Constraint in .Net Generics
How to Seed a Random Class to Avoid Getting Duplicate Random Values
What Operations Are Atomic in C#
Weird Error Upgrading ASP.NET MVC from 4 to 5
Tolist()-- Does It Create a New List