Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Nuget dependencies in my build output?

I am building a modular .NET core application that can load extensions at runtime using MEF. I have 2 projects, one is a library that I want to be able to load at runtime, then I have my main application that will do the loading.

My library project has some Nuget dependencies. In order to load my library at runtime, I need those Nuget dependencies to be available next to the library at runtime, but building using VS2017 does not include these Nuget DLLs as part of the output.

How do I get Nuget DLLs included when I build my library?

Edit: I have tried dotnet publish and dotnet pack, but both of those make me a nupkg file only containing my DLL and not the nuget DLLs I need with it. Also, I can't load a nupkg file at runtime very easily, which is why I'd like to just get the resulting assemblies themselves on their own.

For what it's worth, this is what my csproj looks like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <AssemblyName>JSON.plugin</AssemblyName>
    <IncludeBuiltProjectOutputGroup>true</IncludeBuiltProjectOutputGroup>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Composition" Version="1.0.31" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\BDDGen.Types\BDDGen.Types.csproj" />
  </ItemGroup>

</Project>
like image 776
ldam Avatar asked Aug 02 '17 14:08

ldam


People also ask

Does NuGet package include dependencies?

Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.

How do I add NuGet package source to Visual Studio?

In Visual Studio, select Tools, and then select Options. Select NuGet Package Manager, and then select Package Sources. Enter the feed's Name and Source URL, and then select the green (+) sign to add a new package source.


1 Answers

In order to make the build process copy all referenced dll files from NuGet packages from the cache folder into the build output, set this property inside a <PropertyGroup>:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
like image 96
Martin Ullrich Avatar answered Sep 21 '22 09:09

Martin Ullrich