Search code examples
c#visual-studiodllconsole-applicationexe

How do you make an exe run without needing all the dll files in the same directory?


So I'm trying to merge all of my DLL files into my exe if it's possible so I can run the exe without needing the DLL files in the same directory I tried looking around for other people asking the same question but didn't really find anything helpful or anything I could personally follow.

enter image description here

enter image description here

Thanks in advance for the help


Solution

  • Option 1: .NET Core >3.x, .NET 5

    From Single-file deployment you can edit your project file to contain the following

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0</TargetFramework>
        <PublishSingleFile>true</PublishSingleFile>
        <SelfContained>true</SelfContained>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>
        <PublishTrimmed>true</PublishTrimmed>
        <PublishReadyToRun>true</PublishReadyToRun>
      </PropertyGroup>
    
    </Project>
    

    Which corresponds to running the CLI tool: dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true

    Option 2: .NET Framework

    Before the single-file deployment was available (in .NET Framework), I personally used Fody Costura. Fody is an assembly weaver which, after installing, puts some commands into the MSBuild configuration of your project that enable you to do many things. One add-in is Costura, it weaves your dependencies into a single assembly.