-2

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

Max
  • 13
  • 1
  • 3
    When you publish your project, select the Deployment mode as "Self-contained" under Profile settings, and under the File Publish options, select "Produce single file". This will generate a single working .exe file for your project (along with a .pdb file) – Yash Gupta Jun 12 '21 at 14:20
  • Do you ask how to manage the GAC? To embed DLLs in the EXE? To use a shared folder? Or to run without any DLLs(?)? Otherwise what? –  Jun 12 '21 at 14:40
  • Yes, that, is possible: see for example https://stackoverflow.com/questions/189549/embedding-dlls-in-a-compiled-executable and search the web for "*c# embed dll in executable*". –  Jun 12 '21 at 14:50
  • @Max - click on "Show all", and then you'll find the Deployment mode setting. Select "Self contained" Deployment mode. Then, select your specific Target Runtime. Once you select your Target Runtime, you'll see additional "File Publish options". In there, check the "Produce Single file" checkbox. – Yash Gupta Jun 12 '21 at 14:56

1 Answers1

4

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.

Sorashi
  • 816
  • 1
  • 9
  • 31