.net core package dependencies

2019-09-12 01:05发布

问题:

I'm wanting to build a native .NET Core executable that I can deploy but when I publish the project, the compiler exports all the dependencies into the same directory and the executable needs them to run on a system that doesn't have .NET Core runtime installed. Is there a way to compile/package the DLL's in with the project DLL or executable? Thanks.

回答1:

For merging dependencies into the compiled assembly, check out Costura for Fody:

https://github.com/Fody/Fody

https://github.com/Fody/Costura

I've used it before, and it works well. You can define certain dependencies to merge in a file called FodyWeavers.xml (see the Costura-Fody link for examples).

So, for example (taken from the Costura README.md) you can have two dependencies 'Foo' and 'Bar' that can be merged into your target assembly as follows in the FodyWeavers.xml file.

<Costura>
    <IncludeAssemblies>
        Foo
        Bar
    </IncludeAssemblies>
</Costura>

Other than that, ILMerge is a fine way to go: https://www.nuget.org/packages/ilmerge

EDIT: Found a link describing deploying required .NET core dependencies in a self-contained application: http://druss.co/2016/08/deploy-and-run-net-core-application-without-installed-runtime-self-contained-applications/