-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathApplication.cs
210 lines (183 loc) · 7.88 KB
/
Application.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using ILRepacking.Steps;
using Mono.Cecil;
namespace ILRepacking
{
internal class Application
{
[STAThread]
static int Main(string[] args)
{
if (args.Contains("--version"))
{
Console.WriteLine(typeof(Application).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
return 0;
}
RepackLogger logger = new RepackLogger();
RepackOptions options = null;
int returnCode = -1;
try
{
options = new RepackOptions(args);
if (options.ShouldShowUsage)
{
Usage();
if (options.PauseBeforeExit)
{
Pause();
}
Exit(2);
}
try
{
options.Validate();
}
catch (Exception argumentException)
{
Error(argumentException.Message);
return -2;
}
ILRepack repack = new ILRepack(options, logger);
repack.Repack();
returnCode = 0;
}
catch (RepackOptions.InvalidTargetKindException e)
{
Error(e.Message);
Exit(2);
}
catch (Exception e)
{
string error = e.ToString();
if (e is AssemblyResolutionException or FileNotFoundException)
{
error = e.Message;
}
// we've already printed the error earlier
if (error.StartsWith("System.InvalidOperationException: ILRepack does not support merging"))
{
error = null;
}
if (error != null)
{
logger?.LogError(error);
}
returnCode = 1;
}
finally
{
logger?.Close();
if (options != null && options.PauseBeforeExit)
{
Pause();
}
}
return returnCode;
}
private static void Pause()
{
Console.WriteLine("Press Any Key To Continue");
Console.ReadKey(true);
}
static void Usage()
{
var assembly = typeof(ILRepack).Assembly;
var version =
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ??
assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version.ToString() ?? "";
Console.WriteLine($@"IL Repack {version}
https://github.com/gluck/il-repack
Syntax: ILRepack.exe [Options] /out:<path> <path_to_primary> [<other_assemblies> ...]
- /help displays this help
- @<path>.rsp response file containing additional arguments, one per line
- /log:<logfile> enable logging to a file (default is disabled)
- /verbose more detailed logging
- /out:<path> target assembly path, symbol/config/doc files will be written here as well
- <path_to_primary> primary assembly, gives the name, version to the merged one
- <other_assemblies> other assemblies to merge with the primary one
- /wildcards allows (and resolves) file wildcards (e.g. *.dll) in input assemblies
- /lib:<path> path(s) to search directories to resolve referenced assemblies
(can be specified multiple times).
If you get 'unable to resolve assembly' errors specify a path to a directory
where the assembly can be found.
- /target:kind target assembly kind [library|exe|winexe], default is same as primary assembly
- /ver:M.X.Y.Z target assembly version
- /keyfile:<path> keyfile to sign the output assembly
- /keycontainer:<c> key container
- /delaysign set the key, but don't sign the assembly
- /internalize make all types except in the first assembly 'internal'.
Types in the transitive closure of public API remain public.
- /internalizeassembly:<path>
Internalize a specific assembly name (no extension).
May be specified more than once (one per assembly to internalize).
If specified, no need to also specify /internalize.
- /internalize:<exclude_file>
Each line is either a regex/ full type name not to internalize
or an assembly name not to internalize (.dll extension optional)
- /renameinternalized
rename each internalized type to a new unique name
- /excludeinternalizeserializable
do not internalize types marked as Serializable
- /allowdup:Type keep duplicates of the specified type, may be specified more than once
- /allowdup if no other /allowdup arguments specified, allow all duplicate types
- /union merges types with identical names into one
- /repackdrop:RepackDropAttribute
allows dropping members denoted by this attribute name when merging
- /allowduplicateresources
allows to duplicate resources in output assembly (by default they're ignored)
- /noRepackRes do not add the resource '{ResourcesRepackStep.ILRepackListResourceName}' with all merged assembly names
- /copyattrs copy assembly attributes (by default only the primary assembly attributes are copied)
- /attr:<path> take assembly attributes from the given assembly file
- /allowMultiple when copyattrs is specified, allows multiple attributes (if type allows)
- /targetplatform:P specify target platform (v1, v1.1, v2, v4 supported)
- /keepotherversionreferences
take reference assembly version into account when removing references
- /preservetimestamp preserve original file PE timestamp
- /skipconfig skips merging config files
- /illink merge IL Linker files
- /xmldocs merges XML documentation as well
- /ndebug disables symbol file generation (omit this if you want symbols and debug information)
- /zeropekind allows assemblies with Zero PeKind (but obviously only IL will get merged)
- /index stores file:line debug information as type/method attributes (requires PDB)
- /parallel use as many CPUs as possible to merge the assemblies
- /pause pause execution once completed (good for debugging)
- /usefullpublickeyforreferences - NOT IMPLEMENTED
- /align - NOT IMPLEMENTED
- /closed - NOT IMPLEMENTED
Note: for compatibility purposes, all Options are case insensitive, and can be specified using '/', '-' or '--' prefix.");
}
public static void Error(string text)
{
Write(text, ConsoleColor.Red, writer: Console.Error);
}
public static void Write(
string message,
ConsoleColor color = ConsoleColor.Gray,
bool newLineAtEnd = true,
TextWriter writer = null)
{
writer ??= Console.Out;
lock (writer)
{
var oldColor = Console.ForegroundColor;
Console.ForegroundColor = color;
if (newLineAtEnd)
{
writer.WriteLine(message);
}
else
{
writer.Write(message);
}
Console.ForegroundColor = oldColor;
}
}
static void Exit(int exitCode)
{
Environment.Exit(exitCode);
}
}
}