Ejemplo n.º 1
0
        public void ImportEntryPoints()
        {
            ILStrip strip = new ILStrip(TestHelper.TranslatePath("ILStripWinFormsTestLib.exe"));

            strip.ImportEntryPoints(TestHelper.TranslatePath("ILStripTestLib.dll"), new string[] { "ILStripTest.ExternalLibUser" });

            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");
        }
Ejemplo n.º 2
0
        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.EntryPointBamls)
                {
                    ilStrip.EntryPointBamls.Add(s);
                }

                foreach (string a in options.ImportEntryPoints)
                {
                    ilStrip.ImportEntryPoints(a);
                }

                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);
                }

                try
                {
                    ilStrip.Save(options.OutputFilename);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"[{e.GetType().Name}]: {e.Message}");
#if DEBUG
                    Console.ReadKey();
#endif
                    return(1);
                }
            }

#if DEBUG
            Console.WriteLine("Done.");
            Console.ReadKey();
#endif
            return(0);
        }