-
Notifications
You must be signed in to change notification settings - Fork 2
/
ILMerge.cs
81 lines (64 loc) · 3.15 KB
/
ILMerge.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Microsoft.Build.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace GK
{
public class ILMerge : BuildTaskBase
{
[Required]
public string[] InputAssemblies { get; set; }
public string OutputFileName { get; set; }
public string[] SearchDirectories { get; set; }
public bool Log { get; set; }
public bool Internalize { get; set; }
public string[] InternalizeExclude { get; set; }
public string InternalizeExcludeFile { get; set; }
public string TargetPlatform { get; set; }
public string TargetPlatformDir { get; set; }
public bool WildCards { get; set; }
public override bool Execute()
{
if (string.IsNullOrEmpty(OutputFileName))
OutputFileName = InputAssemblies[0];
if (!Directory.Exists(Path.GetDirectoryName(OutputFileName)))
Directory.CreateDirectory(Path.GetDirectoryName(OutputFileName));
var cleanupExcludeFile = false;
if (InternalizeExclude != null && InternalizeExclude.Length > 0)
{
InternalizeExcludeFile = Path.GetTempFileName();
File.WriteAllLines(InternalizeExcludeFile, InternalizeExclude);
cleanupExcludeFile = true;
}
var ilmSearchPath = Path.GetFullPath(Path.Combine(Assembly.GetExecutingAssembly().Location, "..", ".."));
var ilMergePath = Directory.GetFiles(ilmSearchPath, "ilmerge.exe", SearchOption.AllDirectories).Max();
var args = new StringBuilder();
if (SearchDirectories != null && SearchDirectories.Length > 0)
args.Append(string.Join("", SearchDirectories.Select(x => string.Format(@" /lib:""{0}""", x.TrimEnd('\\')))));
if (Log)
args.Append(" /log");
if (!string.IsNullOrWhiteSpace(InternalizeExcludeFile))
args.AppendFormat(@" /internalize:""{0}""", InternalizeExcludeFile);
else if (Internalize)
args.Append(" /internalize");
if (!string.IsNullOrWhiteSpace(TargetPlatform))
args.AppendFormat(@" /targetplatform:{0}", TargetPlatform);
if (!string.IsNullOrWhiteSpace(TargetPlatformDir))
args.AppendFormat(@",""{0}""", TargetPlatformDir);
if (WildCards)
args.Append(" /wildcards");
args.AppendFormat(@" /out:""{0}""", OutputFileName);
args.Append(string.Join("", InputAssemblies.Select(x => @" """ + x + @"""")));
var ilMergeProc = new ProcessHostRedirect() { FileName = ilMergePath, Arguments = args.ToString().Trim() };
ilMergeProc.CommandLinePrefix = "";
ilMergeProc.OutputDataHandler = (dataType, line) => { LogLine(line); };
ilMergeProc.Execute();
if (cleanupExcludeFile)
File.Delete(InternalizeExcludeFile);
return true;
}
}
}