Skip to content

Instantly share code, notes, and snippets.

@patrykbuzowicz
Created January 29, 2019 20:31
Show Gist options
  • Save patrykbuzowicz/29437bcc2996dd03909ae6b77d668d5b to your computer and use it in GitHub Desktop.
Save patrykbuzowicz/29437bcc2996dd03909ae6b77d668d5b to your computer and use it in GitHub Desktop.
Merges the output exe and all dlls into a single exe. Places a new $(ProjectName).Merged.exe binary in the /bin/Release/net461 output directory
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.8.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>
<Target Name="RemovePdbs" Condition=" '$(Configuration)' == 'Release' " AfterTargets="PostBuildEvent">
<ItemGroup>
<PdbFiles Include="$(OutDir)%(DestinationSubDirectory)\*.pdb" />
</ItemGroup>
<Message Importance="high" Text="Cleaning PDB files..." />
<Delete Files="@(PdbFiles)" />
</Target>
<Target Name="ILMerge" Condition=" '$(Configuration)' == 'Release' " AfterTargets="RemovePdbs">
<PropertyGroup>
<ExeToMerge>$(OutDir)$(MSBuildProjectName).exe</ExeToMerge>
</PropertyGroup>
<ItemGroup>
<DllsToMerge Include="$(OutDir)%(DestinationSubDirectory)\*.dll" />
</ItemGroup>
<Message Importance="high" Text="Executing ILMerge..." />
<Exec Command="&quot;$(SolutionDir)lib\ILMerge.exe&quot; /out:&quot;$(OutDir)$(MSBuildProjectName).Merged.exe&quot; &quot;$(ExeToMerge)&quot; @(DllsToMerge->'&quot;%(FullPath)&quot;', ' ')" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment