Example #1
0
 public ILMerge()
 {
     mergeSession = new ILMerging.ILMerge();
 }
        private void ILMerge()
        {
            try
            {
                btnOK.Enabled = false;

                ILMerging.ILMerge ilm = new ILMerging.ILMerge();
                //ilm.Closed = true;

                if (!String.IsNullOrEmpty(txtKeyFile.Text))
                    ilm.KeyFile = txtKeyFile.Text;

                string[] assemblies = new string[lbAssemblies.Items.Count];
                for (int i = 0, j = 1; i < lbAssemblies.Items.Count; i++)
                {
                    if (i == lbAssemblies.SelectedIndex)
                    {
                        assemblies[0] = Path.Combine(_sourceDir, lbAssemblies.Items[i].ToString());
                    }
                    else
                    {
                        assemblies[j++] = Path.Combine(_sourceDir, lbAssemblies.Items[i].ToString());
                    }
                }
                ilm.SetInputAssemblies(assemblies);

                string outputFile = Path.GetFileName(assemblies[0]);
                outputFile = Path.Combine(txtOutputDir.Text, outputFile);
                if (File.Exists(outputFile))
                {
                    string ext = Path.GetExtension(outputFile);
                    outputFile = Path.ChangeExtension(outputFile, ".ILMerge" + ext);
                }
                ilm.OutputFile = outputFile;

                ilm.Closed = chkClosed.Checked;
                ilm.DebugInfo = chkDebug.Checked;
                if (chkDuplicate.Checked) ilm.AllowDuplicateType(null);
                
                //ilm.Log = true;
                ilm.Merge();
                ilm = null;

                SimpleTextbox.AppendText(txtInfo, String.Format("Output File: {0}\r\n\r\n", outputFile));

            }
            catch (Exception ex)
            {
                SimpleTextbox.AppendText(txtInfo, String.Format("{0}\r\n\r\n", ex.Message));
            }
            finally
            {
                btnOK.Enabled = true;
            }

            Application.DoEvents();
        }
Example #3
0
        public override bool Execute()
        {

            try
            {
                if (mergeSession == null)
                    mergeSession = new ILMerging.ILMerge();

                mergeSession.AllowMultipleAssemblyLevelAttributes = this.AllowMultipleAssemblyLevelAttributes;
                mergeSession.AllowWildCards = this.AllowWildCards;
                mergeSession.AllowZeroPeKind = this.AllowZeroPeKind;
                mergeSession.AttributeFile = this.AttributeFile;
                mergeSession.Closed = this.Closed;
                mergeSession.CopyAttributes = this.CopyAttributes;
                mergeSession.DebugInfo = this.DebugInfo;
                mergeSession.DelaySign = this.DelaySign;
                mergeSession.ExcludeFile = this.ExcludeFile;
                mergeSession.FileAlignment = this.FileAlignment;
                mergeSession.Internalize = this.Internalize;
                mergeSession.KeyFile = this.KeyFile;
                mergeSession.Log = this.EnableLog;
                mergeSession.LogFile = this.LogFile;
                mergeSession.OutputFile = this.OutputFile;
                mergeSession.PreserveShortBranches = this.PreserveShortBranches;
                mergeSession.PublicKeyTokens = this.PublicKeyTokens;
                mergeSession.UnionMerge = this.UnionMerge;
                mergeSession.Version = this.Version;
                mergeSession.XmlDocumentation = this.XmlDocumentation;

                List<string> assembliesToMerge = new List<string>();

                if (InputAssemblies == null || InputAssemblies.Length == 0)
                {
                    throw new ArgumentException("InputAssemblies parameter can't be null and should be non-zero length!",
                        "InputAssemblies");
                }

                foreach (ITaskItem item in InputAssemblies)
                {
                    assembliesToMerge.Add(item.ItemSpec);
                }

                mergeSession.SetInputAssemblies(assembliesToMerge.ToArray());

                if (SearchPaths != null && SearchPaths.Length > 0)
                {

                    var assemblySearchPaths = new List<string>() { "." };

                    foreach (ITaskItem item in SearchPaths)
                    {
                        if (!String.IsNullOrEmpty(item.ItemSpec))
                        {
                            assemblySearchPaths.Add(Path.Combine(BuildEngine.ProjectFileOfTaskNode, item.ItemSpec));
                        }
                    }

                    mergeSession.SetSearchDirectories(assemblySearchPaths.ToArray());
                }

                Log.LogMessage(MessageImportance.Normal, "Merging {0} assemblies to '{1}'.", assembliesToMerge.Count, OutputFile);
                mergeSession.Merge();
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
                return false;
            }

            return true;
        } 
        private void ILMerge()
        {
            try
            {
                btnOK.Enabled = false;

                ILMerging.ILMerge ilm = new ILMerging.ILMerge();
                //ilm.Closed = true;

                if (!String.IsNullOrEmpty(txtKeyFile.Text))
                {
                    ilm.KeyFile = txtKeyFile.Text;
                }

                string[] assemblies = new string[lbAssemblies.Items.Count];
                for (int i = 0, j = 1; i < lbAssemblies.Items.Count; i++)
                {
                    if (i == lbAssemblies.SelectedIndex)
                    {
                        assemblies[0] = Path.Combine(_sourceDir, lbAssemblies.Items[i].ToString());
                    }
                    else
                    {
                        assemblies[j++] = Path.Combine(_sourceDir, lbAssemblies.Items[i].ToString());
                    }
                }
                ilm.SetInputAssemblies(assemblies);

                string outputFile = Path.GetFileName(assemblies[0]);
                outputFile = Path.Combine(txtOutputDir.Text, outputFile);
                if (File.Exists(outputFile))
                {
                    string ext = Path.GetExtension(outputFile);
                    outputFile = Path.ChangeExtension(outputFile, ".ILMerge" + ext);
                }
                ilm.OutputFile = outputFile;

                ilm.Closed    = chkClosed.Checked;
                ilm.DebugInfo = chkDebug.Checked;
                if (chkDuplicate.Checked)
                {
                    ilm.AllowDuplicateType(null);
                }

                //ilm.Log = true;
                ilm.Merge();
                ilm = null;

                SimpleTextbox.AppendText(txtInfo, String.Format("Output File: {0}\r\n\r\n", outputFile));
            }
            catch (Exception ex)
            {
                SimpleTextbox.AppendText(txtInfo, String.Format("{0}\r\n\r\n", ex.Message));
            }
            finally
            {
                btnOK.Enabled = true;
            }

            Application.DoEvents();
        }