Usage - ILStrip

Code Example

In the reasons of convenience, all operations are divided into separate methods, that should be called in sequence:

ILStrip stripper =
  new ILStrip(inputPath), 
// new ILStrip(inputStream), 
// new ILStrip(assemblyDefinition), 
// add whatever you want by name.
// executable's Main(string[] args) will be added automatically
// walk the assembly opcodes to find all types and references used

// walk the assembly types to build list of all types that aren't used

// remove all unused types

// exclude necessary resources from cleanup

// exclude necessary WPF resources from cleanup

// remove all unused WinForms and WPF resources

// remove all unused references

// exclude the target public API

// hide all other with internal

// stripper.Save(outputStream), 

Commandline Tool

In reasons of convenience there is a commandline tool, built from improvised means. This makes the ILStrip to work as standalone or as a part of any build script. Usage:


BrokenEvent.ILStrip.CLI.exe input output [-s] [-e MyNamespace.MyClass] [-h]
[-he MyNamespace.MyClass] [-u] [-re MyNamespace.MyResource]
[-we resources/myresource.png] [-import myApp.exe]


input           Input assembly filename to process. Required.
output          Output assembly filename to save processed assembly. Required.
-s, -silent     Suppresses logging. Optional.
-e              User defined entry point classes list to start analysis. Multiple values. Optional.
-h, -hide       Hide public API with internal access modifier. Optional.
-he             Exclusions for -h option. Multiple values. Optional.
-u              Removes all unknown resources. Optional.
-re             Resource exclusions for -u option. Multiple values. Optional.
-we             WPF Resource exclusions for -u option. Multiple values. Optional.
-import         List of assemblies which use current to import used types as entry points. Optional.

MSBuild Task of NuGet Package

This information applies only to BrokenEvent.ILStrip.CLI package.

The package will install MSBuild target when installed by the NuGet. By default this target allows to strip the target binary to optimize its filesize.

If you use ILRepack, the target binary filename may be changed, so the ILStrip's target couldn't find target file and will fail.

To control the target, you may use the following MSBuild properties:


  • ILStripInternalize - whether to hide public types of stripped binary with internal. Boolean value (True/False). Feature is disabled by default.
  • ILStripSrc - name of source file to process. By default it is assembly name + default extension.
  • ILStripDst - name of destionation file to to write assembly after processing. By default it is assembly name + default extension.


  • ILStripEntryPoints - list of custom entry points to start scanning from. For xecutables the Program class will be added by default. Format is Namespace.ClassName. Example: WindowsFormsApp5.Program.
  • ILStripEntryPointBAMLs - list of custom entry point BAMLs. When you load .xaml by filename this couldn't be detected with IL scanning, so you should use this ItemGroup in such cases.
  • ILStripHideExclusions - list of types to exclude from hiding with internal. Meaningless if ILStripInternalize not set to True.
  • ILStripImport - list of filenames of assemblies to import types used by them as entry points.


The most simple way to add custom properties to MSBuild of Visual Studio project is to create a file named Directory.Build.props at root of project.

Example of such file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="">

    <ILStripEntryPoints Include="WindowsFormsApp5.Program"/>
    <ILStripEntryPoints Include="WindowsFormsApp5.Class1"/>
    <ILStripEntryPointBAMLs Include="ui/mainwindow.baml"/>
    <ILStripHideExclusions Include="WindowsFormsApp5.Class1"/>
    <ILStripImport Include="mylib.dll"/>