public void EntryPoints() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripTestLib.dll")); strip.EntryPoints.Add("ILStripTest.UserClass"); strip.ScanUsedClasses(); strip.ScanUnusedClasses(); strip.CleanupUnusedClasses(); AssemblyAsserts asserts = new AssemblyAsserts(strip); asserts.AssertClass("ILStripTest.UserClass"); asserts.AssertClass("ILStripTest.EmptyClass"); asserts.AssertClass("ILStripTest.AttributedClass"); asserts.AssertNoClass("ILStripTest.ClassWithAttributedField"); asserts.AssertNoClass("ILStripTest.ClassWithAttributedProperty"); asserts.AssertNoClass("ILStripTest.ClassWithTypeRefAttributeProperty"); asserts.AssertNoClass("ILStripTest.ClassWithGeneric`1"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass/NestedClass"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass2"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass2/NestedClass"); asserts.AssertNoClass("ILStripTest.ClassWithEvents"); asserts.AssertClass("ILStripTest.IInterface"); asserts.AssertClass("ILStripTest.CustomAttribute"); asserts.AssertNoClass("ILStripTest.XmlUsingClass"); }
public void CleanupUnusedReferencesAll() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripTestLib.dll")); strip.ScanUsedClasses(); strip.ScanUnusedClasses(); strip.CleanupUnusedClasses(); strip.CleanupUnusedReferences(); AssemblyAsserts asserts = new AssemblyAsserts(strip); asserts.AssertNoClass("ILStripTest.EmptyClass"); asserts.AssertNoClass("ILStripTest.AttributedClass"); asserts.AssertNoClass("ILStripTest.ClassWithAttributedField"); asserts.AssertNoClass("ILStripTest.ClassWithAttributedProperty"); asserts.AssertNoClass("ILStripTest.ClassWithTypeRefAttributeProperty"); asserts.AssertNoClass("ILStripTest.UserClass"); asserts.AssertNoClass("ILStripTest.ClassWithGeneric`1"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass/NestedClass"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass2"); asserts.AssertNoClass("ILStripTest.ClassWithNestedClass2/NestedClass"); asserts.AssertNoClass("ILStripTest.ClassWithEvents"); asserts.AssertNoClass("ILStripTest.IInterface"); asserts.AssertNoClass("ILStripTest.CustomAttribute"); asserts.AssertNoClass("ILStripTest.XmlUsingClass"); asserts.AssertReference("mscorlib"); // can't be removed asserts.AssertNoReference("System.Xml"); asserts.AssertNoReference("ILStripWinFormsTestLib"); }
private static byte[] GetOptimizedBytes(string path) { Environment.CurrentDirectory = Path.GetDirectoryName(path) ?? throw new ArgumentException("Path not found"); string asmNameExt = Path.GetFileName(path); string asmName = Path.GetFileNameWithoutExtension(asmNameExt); string asmNameMerged = $"{asmName}.merged{Path.GetExtension(asmNameExt)}"; string asmNameMinified = $"{asmName}.minified{Path.GetExtension(asmNameExt)}"; Assembly asm = Assembly.LoadFrom(path); ILRepack repack = new ILRepack(new RepackOptions(new[] { "/internalize", $"/out:{asmNameMerged}", asmNameExt }.Concat(GetDependentFilesPass(asm, Environment.CurrentDirectory)))); repack.Repack(); ILStrip optimizer = new ILStrip(asmNameMerged); optimizer.MakeInternal(); optimizer.ScanUsedClasses(); optimizer.ScanUnusedClasses(); optimizer.CleanupUnusedClasses(); optimizer.CleanupUnusedResources(); optimizer.CleanupUnusedReferences(); optimizer.Save(asmNameMinified); optimizer.Dispose(); File.Delete(asmNameMerged); byte[] result = File.ReadAllBytes(asmNameMinified); File.Delete(asmNameMinified); return(result); }
public void MainWindowBamlEntryPoint() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripWPFTestLib.exe")); strip.EntryPointBamls.Add("ui/mainwindow.baml"); strip.ScanUsedClasses(); strip.ScanUnusedClasses(); strip.CleanupUnusedClasses(); strip.CleanupUnusedResources(); AssemblyAsserts asserts = new AssemblyAsserts(strip); asserts.AssertClass("ILStripWPFTestLib.App"); asserts.AssertClass("ILStripWPFTestLib.UI.MainWindow"); asserts.AssertClass("ILStripWPFTestLib.UI.UsedControl"); asserts.AssertClass("ILStripWPFTestLib.ViewModel.UsedViewModel"); asserts.AssertClass("ILStripWPFTestLib.ViewModel.Converters.UsedValueConverter"); asserts.AssertNoClass("ILStripWPFTestLib.UI.UnusedWindow"); asserts.AssertNoClass("ILStripWPFTestLib.UI.UnusedControl"); asserts.AssertNoClass("ILStripWPFTestLib.ViewModel.UnusedViewModel"); asserts.AssertNoClass("ILStripWPFTestLib.ViewModel.Converters.UnusedValueConverter"); asserts.AssertClass("ILStripWPFTestLib.ViewModel.TestExtension"); asserts.AssertClass("ILStripWPFTestLib.ViewModel.StaticClass"); asserts.AssertClass("ILStripWPFTestLib.ViewModel.AnotherStaticClass"); asserts.AssertWpfResource("ui/mainwindow.baml"); asserts.AssertNoWpfResource("ui/unusedwindow.baml"); asserts.AssertNoWpfResource("testdictionary.baml"); }
public void RemoveUnknownResourcesExcluded() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripWinFormsTestLib.exe")); strip.UnusedResourceExclusions.Add("ILStripWinFormsTestLib.Resources.BrokenEventLogo.png"); strip.RemoveUnknownResources = true; strip.ScanUsedClasses(); strip.ScanUnusedClasses(); strip.CleanupUnusedClasses(); strip.CleanupUnusedResources(); AssemblyAsserts asserts = new AssemblyAsserts(strip); asserts.AssertClass("ILStripWinFormsTestLib.UsedForm"); asserts.AssertClass("ILStripWinFormsTestLib.ControlOfUsedForm"); asserts.AssertNoClass("ILStripWinFormsTestLib.UnusedForm"); asserts.AssertNoClass("ILStripWinFormsTestLib.ControlOfUnusedForm"); asserts.AssertResource("ILStripWinFormsTestLib.UsedForm.resources"); asserts.AssertNoResource("ILStripWinFormsTestLib.UnusedForm.resources"); asserts.AssertResource("ILStripWinFormsTestLib.Resources.BrokenEventLogo.png"); asserts.AssertReference("mscorlib"); asserts.AssertReference("System.Drawing"); asserts.AssertReference("System.Windows.Forms"); }
public void EntryPointForm() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripWinFormsTestLib.exe")); strip.EntryPoints.Add("ILStripWinFormsTestLib.UnusedForm"); strip.ScanUsedClasses(); strip.ScanUnusedClasses(); strip.CleanupUnusedClasses(); strip.CleanupUnusedResources(); strip.CleanupUnusedReferences(); AssemblyAsserts asserts = new AssemblyAsserts(strip); asserts.AssertClass("ILStripWinFormsTestLib.UsedForm"); asserts.AssertClass("ILStripWinFormsTestLib.ControlOfUsedForm"); asserts.AssertClass("ILStripWinFormsTestLib.UnusedForm"); asserts.AssertClass("ILStripWinFormsTestLib.ControlOfUnusedForm"); asserts.AssertResource("ILStripWinFormsTestLib.UsedForm.resources"); asserts.AssertResource("ILStripWinFormsTestLib.UnusedForm.resources"); asserts.AssertResource("ILStripWinFormsTestLib.Resources.BrokenEventLogo.png"); asserts.AssertReference("mscorlib"); asserts.AssertReference("System.Drawing"); asserts.AssertReference("System.Windows.Forms"); }
public void SelfAttributing() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripTestLib.dll")); strip.EntryPoints.Add("ILStripTest.SelfAttributingAttribute"); // this call will fail (and fail test runner) with StackOverflowException which we're unable to catch strip.ScanUsedClasses(); }
public void CollectExternalUsages() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripTestLib.dll")); strip.CollectUsageFromReferences = true; strip.EntryPoints.Add("ILStripTest.ExternalLibUser"); strip.ScanUsedClasses(); CollectionAssert.AreEqual(new string[] { "ILStripWinFormsTestLib.UnusedForm" }, strip.GetUsagesFromReference("ILStripWinFormsTestLib")); }
public void RemoveUnknownResourcesUnused() { ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripWPFTestLib.exe")); strip.EntryPoints.Add("ILStripWPFTestLib.UI.MainWindow"); strip.RemoveUnknownResources = true; strip.ScanUsedClasses(); strip.ScanUnusedClasses(); strip.CleanupUnusedClasses(); strip.CleanupUnusedResources(); AssemblyAsserts asserts = new AssemblyAsserts(strip); asserts.AssertNoWpfResource("resources/brokeneventlogo.png"); }
static int Main(string[] args) { CommandLineOptions options = new CommandLineOptions(); CommandLineParser <CommandLineOptions> parser = new CommandLineParser <CommandLineOptions>(options); parser.AssignmentSyntax = true; parser.WriteUsageOnError = true; if (!parser.Parse(args)) { #if DEBUG Console.ReadKey(); #endif return(1); } if (!options.Silent) { Console.WriteLine("Reading: " + options.InputFilename); } using (ILStrip ilStrip = new ILStrip(options.InputFilename)) { if (!options.Silent) { ilStrip.Logger = new CommandLineLogger(); } foreach (string s in options.EntryPoints) { ilStrip.EntryPoints.Add(s); } foreach (string s in options.ResourceExclusions) { ilStrip.UnusedResourceExclusions.Add(s); } foreach (string s in options.WpfResourceExclusions) { ilStrip.UnusedWpfResourceExclusions.Add(s); } ilStrip.RemoveUnknownResources = options.RemoveUnknownResources; ilStrip.ScanUsedClasses(); ilStrip.ScanUnusedClasses(); ilStrip.CleanupUnusedClasses(); ilStrip.CleanupUnusedReferences(); ilStrip.CleanupUnusedResources(); if (options.HideApi) { foreach (string s in options.HideExclusions) { ilStrip.MakeInternalExclusions.Add(s); } ilStrip.MakeInternal(); } if (!options.Silent) { Console.WriteLine("Writing: " + options.OutputFilename); } ilStrip.Save(options.OutputFilename); } #if DEBUG Console.ReadKey(); #endif return(0); }
static int Main(string[] args) { CommandLineOptions options = new CommandLineOptions(); CommandLineParser parser = new CommandLineParser(options); parser.Parse(); if (parser.HasErrors) { Console.WriteLine(parser.UsageInfo.ToString(78, true)); #if DEBUG Console.ReadKey(); #endif return(1); } if (options.DoHelp) { Console.WriteLine(parser.UsageInfo.ToString()); #if DEBUG Console.ReadKey(); #endif return(0); } if (!options.Silent) { Console.WriteLine("BrokenEvent.ILStrip.CLI, (C)2017, Broken Event"); } if (!options.Silent) { Console.WriteLine("Reading: " + options.InputFilename); } ILStrip ilStrip = new ILStrip(options.InputFilename); if (!options.Silent) { ilStrip.Logger = new CommandLineLogger(); } foreach (string s in options.EntryPoints) { ilStrip.EntryPoints.Add(s); } ilStrip.ScanUsedClasses(); ilStrip.ScanUnusedClasses(); if (options.CleanUnusedClasses) { ilStrip.CleanupUnusedClasses(); } if (options.CleanUnusedReferences) { ilStrip.CleanupUnusedReferences(); } if (options.CleanUnusedResources) { ilStrip.CleanupUnusedResources(); } if (options.HideApi) { foreach (string s in options.HideExclusions) { ilStrip.MakeInternalExclusions.Add(s); } ilStrip.MakeNotPublic(); } if (!options.Silent) { Console.WriteLine("Writing: " + options.OutputFilename); } ilStrip.Save(options.OutputFilename); #if DEBUG Console.ReadKey(); #endif return(0); }