Beispiel #1
0
        public async Task OnExport()
        {
            var view = (MessageViewModel)IoC.Get <IModule>();

            view.Title = "Info";
            var merge = new ILMerging.ILMerge();

            if (Items is null || MainFilePath is null || ExportFileName is null || ExportPath is null || Items.Count < 1 || MainFilePath.Length < 1 || ExportPath.Length < 1 || ExportFileName.Length < 1)
            {
                view.Content = "配置错误";
                windowManager.ShowDialog(view);
                return;
            }

            var data = Items.ToList <string>();

            data.Add(MainFilePath);
            merge.SetInputAssemblies(data.ToArray());
            var      outpath  = Path.Combine(ExportPath, ExportFileName);
            FileInfo fileInfo = new FileInfo(outpath);

            if (!fileInfo.Extension.Contains("dll"))
            {
                MessageBox.Show("the extension of the output file name must be dll.");
                return;
            }
            merge.OutputFile = outpath;
            merge.SetTargetPlatform("v4", string.Empty);
            merge.TargetKind = ILMerging.ILMerge.Kind.SameAsPrimaryAssembly;

            var info = string.Empty;
            await Task.Run(() =>
            {
                try
                {
                    merge.Merge();
                    info = "successfully";
                    windowManager.ShowDialog(view);
                }
                catch (Exception ex)
                {
                    info = ex.Message;
                }
            });

            view.Content = info;
            windowManager.ShowDialog(view);
        }
Beispiel #2
0
        public ActionResult Index(List<string> pacote)
        {
            var pacotesDictionary = this.GetPacotes().ToDictionary(c => c.Id);
            var pacotes = (from p in pacote orderby p != "common" select pacotesDictionary[p]).ToList();

            var merge = new ILMerging.ILMerge();
            merge.KeyFile = Server.MapPath("MTO.snk");

            var path = Server.MapPath("/bin/");
            var input = (from p in pacotes select path + "MTO.Practices." + p.Name + ".dll").ToArray();
            merge.SetInputAssemblies(input);
            merge.OutputFile = Server.MapPath("/tmp/") + "MTO.Practices.dll";
            merge.SetTargetPlatform("v4", @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0");
            merge.Merge();

            return File(merge.OutputFile, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(merge.OutputFile));
        }
        protected override void ExecuteTask()
        {
            if( InputAssemblies.FileNames.Count == 0 )
            {
                Log( Level.Error, "At least one assembly must be included" );
                return;
            }

            var merger = new ILMerging.ILMerge();

            merger.AttributeFile  = AttributeFile;
            merger.Closed         = Closed;
            merger.CopyAttributes = CopyAttributes;
            merger.DebugInfo      = DebugInfo;
            merger.ExcludeFile    = ExcludeFile;
            merger.Internalize    = Internalize;
            merger.LogFile        = LogFile;
            merger.Log            = !string.IsNullOrEmpty( _logFile );
            merger.OutputFile     = OutputFile;
            merger.KeyFile	      = KeyFile;

            if( TargetPlatform != null && TargetPlatformDirectory != null )
                merger.SetTargetPlatform( TargetPlatform, TargetPlatformDirectory );

            if( LibraryPath != null)
                merger.SetSearchDirectories( LibraryPath.DirectoryNames.Cast<string>().ToArray() );

            merger.SetInputAssemblies( InputAssemblies.FileNames.Cast<string>().ToArray() );

            switch( TargetKind.ToLower())
            {
                case "winexe":
                    merger.TargetKind = ILMerging.ILMerge.Kind.WinExe; break;
                case "exe":
                    merger.TargetKind = ILMerging.ILMerge.Kind.Exe; break;
                case "dll":
                    merger.TargetKind = ILMerging.ILMerge.Kind.Dll; break;
                case "sameasprimary":
                    merger.TargetKind = ILMerging.ILMerge.Kind.SameAsPrimaryAssembly;
                    break;
                default:
                    throw new BuildException( "TargetKind must be either exe, dll, winexe or sameasprimary" );
            }

            try
            {
                Log( Level.Info, "Merging assemblies to {0}.", OutputFile );
                merger.Merge();
            }
            catch( Exception e )
            {
                throw new BuildException( "Failed to merge assemblies", e );
            }
        }
        private void Merge()
        {
            string allfiles = this.InputAssemblies.Get(this.ActivityContext).Aggregate(string.Empty, (current, assembly) => current + (assembly + " "));

            this.LogBuildMessage("Merging " + allfiles + " into " + this.OutputFile.Get(this.ActivityContext));
            ILMerging.ILMerge m = new ILMerging.ILMerge();

            if (this.AllowDuplicateTypes.Expression != null)
            {
                foreach (string allowDuplicateType in this.AllowDuplicateTypes.Get(this.ActivityContext))
                {
                    m.AllowDuplicateType(allowDuplicateType);
                }
            }

            if (this.AllowZeroPeKind.Get(this.ActivityContext))
            {
                m.AllowZeroPeKind = true;
            }

            if (this.AttributeFile.Expression != null)
            {
                m.AttributeFile = this.AttributeFile.Get(this.ActivityContext);
            }

            if (this.Closed.Get(this.ActivityContext))
            {
                m.Closed = true;
            }

            if (this.CopyAttributes.Get(this.ActivityContext))
            {
                m.CopyAttributes = true;
            }

            if (!this.DebugInfo.Get(this.ActivityContext))
            {
                m.DebugInfo = true;
            }

            if (this.DelaySign.Get(this.ActivityContext))
            {
                m.DelaySign = true;
            }

            if (this.ExcludeFile.Expression != null)
            {
                m.Internalize = true;
                m.ExcludeFile = this.ExcludeFile.Get(this.ActivityContext);
            }
            else if (this.Internalize.Get(this.ActivityContext))
            {
                m.Internalize = true;
            }

            if (this.KeyFile.Expression != null)
            {
                m.KeyFile = this.KeyFile.Get(this.ActivityContext);
            }

            if (this.LogFile.Expression != null)
            {
                m.LogFile = this.LogFile.Get(this.ActivityContext);
            }

            if (this.PublicKeyTokens.Get(this.ActivityContext))
            {
                m.PublicKeyTokens = true;
            }

            if (this.TargetPlatformVersion.Expression != null)
            {
                m.SetTargetPlatform(this.TargetPlatformVersion.Get(this.ActivityContext), this.TargetPlatformDirectory.Get(this.ActivityContext));
            }

            m.TargetKind = (ILMerging.ILMerge.Kind)Enum.Parse(typeof(ILMerging.ILMerge.Kind), this.TargetKind.Get(this.ActivityContext).ToString());

            if (this.UnionMerge.Get(this.ActivityContext))
            {
                m.UnionMerge = true;
            }

            if (this.Version.Expression != null)
            {
                m.Version = new Version(this.Version.Get(this.ActivityContext));
            }

            if (this.XmlDocs.Get(this.ActivityContext))
            {
                m.XmlDocumentation = true;
            }

            if (this.SearchDirectories.Expression != null)
            {
                var directories = this.SearchDirectories.Get(this.ActivityContext).Split(';');
                m.SetSearchDirectories(directories);
            }

            m.FileAlignment = this.FileAlignment.Get(this.ActivityContext);
            m.OutputFile    = this.OutputFile.Get(this.ActivityContext);
            m.SetInputAssemblies(this.InputAssemblies.Get(this.ActivityContext).ToArray());
            m.Merge();
            this.StrongNameLost.Set(this.ActivityContext, m.StrongNameLost);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            try {
                String strDir = "";
                if (args.Length != 1)
                {
                    Console.WriteLine("Usage: HTMerge directoryName");
                    return;
                }
                else
                {
                    strDir = args[0];
                }

                String[] exeFiles = System.IO.Directory.GetFiles(strDir, "*.exe");
                String[] dllFiles = System.IO.Directory.GetFiles(strDir, "*.dll");

                ArrayList ar = new ArrayList();

                Boolean bAdded = false;

                //there might be more than 1 exe file,
                //we go for the first one that isn't the vshost exe
                foreach (String strExe in exeFiles)
                {
                    if (!strExe.Contains("vshost"))
                    {
                        ar.Add(strExe);
                        bAdded = true;
                        break;
                    }
                }

                if (!bAdded)
                {
                    Console.WriteLine("Error: No exe could be found");
                    //I know multiple returns are bad…
                    return;
                }

                bAdded = false;

                foreach (String strDLL in dllFiles)
                {
                    ar.Add(strDLL);
                    bAdded = true;
                }

                //no point merging if nothing to merge with!
                if (!bAdded)
                {
                    Console.WriteLine("Error: No DLLs could be found");
                    //I know multiple returns are bad…
                    return;
                }


                //You will need to add a reference to ILMerge.exe from Microsoft
                //See http://research.microsoft.com/~mbarnett/ILMerge.aspx
                ILMerging.ILMerge myMerge = new ILMerging.ILMerge();
                myMerge.AllowZeroPeKind = true;
                String[] files = (String[])ar.ToArray(typeof(string));

                String strTargetDir = strDir + "\\Merged";

                try {
                    System.IO.Directory.CreateDirectory(strTargetDir);
                } catch {
                }

                //Here we get the first file name
                //(which was the .exe file) and use that
                // as the output
                String strOutputFile = System.IO.Path.GetFileName(files[0]);

                myMerge.OutputFile = strTargetDir + "\\" + strOutputFile;
                myMerge.SetInputAssemblies(files);

                myMerge.Merge();
            } catch (Exception ex) {
                Console.WriteLine(String.Format("Error :{0}", ex.Message));
            }
        }
        private void Merge()
        {
            string allfiles = this.InputAssemblies.Get(this.ActivityContext).Aggregate(string.Empty, (current, assembly) => current + (assembly + " "));
            this.LogBuildMessage("Merging " + allfiles + " into " + this.OutputFile.Get(this.ActivityContext));
            ILMerging.ILMerge m = new ILMerging.ILMerge();

            if (this.AllowDuplicateTypes.Expression != null)
            {
                foreach (string allowDuplicateType in this.AllowDuplicateTypes.Get(this.ActivityContext))
                {
                    m.AllowDuplicateType(allowDuplicateType);
                }
            }

            if (this.AllowZeroPeKind.Get(this.ActivityContext))
            {
                m.AllowZeroPeKind = true;
            }

            if (this.AttributeFile.Expression != null)
            {
                m.AttributeFile = this.AttributeFile.Get(this.ActivityContext);
            }

            if (this.Closed.Get(this.ActivityContext))
            {
                m.Closed = true;
            }

            if (this.CopyAttributes.Get(this.ActivityContext))
            {
                m.CopyAttributes = true;
            }

            if (!this.DebugInfo.Get(this.ActivityContext))
            {
                m.DebugInfo = true;
            }

            if (this.DelaySign.Get(this.ActivityContext))
            {
                m.DelaySign = true;
            }

            if (this.ExcludeFile.Expression != null)
            {
                m.Internalize = true;
                m.ExcludeFile = this.ExcludeFile.Get(this.ActivityContext);
            }
            else if (this.Internalize.Get(this.ActivityContext))
            {
                m.Internalize = true;
            }

            if (this.KeyFile.Expression != null)
            {
                m.KeyFile = this.KeyFile.Get(this.ActivityContext);
            }

            if (this.LogFile.Expression != null)
            {
                m.LogFile = this.LogFile.Get(this.ActivityContext);
            }

            if (this.PublicKeyTokens.Get(this.ActivityContext))
            {
                m.PublicKeyTokens = true;
            }

            if (this.TargetPlatformVersion.Expression != null)
            {
                m.SetTargetPlatform(this.TargetPlatformVersion.Get(this.ActivityContext), this.TargetPlatformDirectory.Get(this.ActivityContext));
            }

            m.TargetKind = (ILMerging.ILMerge.Kind)Enum.Parse(typeof(ILMerging.ILMerge.Kind), this.TargetKind.Get(this.ActivityContext).ToString());

            if (this.UnionMerge.Get(this.ActivityContext))
            {
                m.UnionMerge = true;
            }

            if (this.Version.Expression != null)
            {
                m.Version = new Version(this.Version.Get(this.ActivityContext));
            }

            if (this.XmlDocs.Get(this.ActivityContext))
            {
                m.XmlDocumentation = true;
            }

            if (this.SearchDirectories.Expression != null)
            {
                var directories = this.SearchDirectories.Get(this.ActivityContext).Split(';');
                m.SetSearchDirectories(directories);
            }

            m.FileAlignment = this.FileAlignment.Get(this.ActivityContext);
            m.OutputFile = this.OutputFile.Get(this.ActivityContext);
            m.SetInputAssemblies(this.InputAssemblies.Get(this.ActivityContext).ToArray());
            m.Merge();
            this.StrongNameLost.Set(this.ActivityContext, m.StrongNameLost);
        }