D'oh, forgot to add g_hash_table_steal() to glib.h
[mono-project/dkf.git] / mcs / tools / gacutil / driver.cs
blob476ad11a9684a544c279f8c8bd1d0e3a53aa39cd
1 //
2 // Mono.Tools.GacUtil
3 //
4 // Author(s):
5 // Todd Berman <tberman@sevenl.net>
6 // Jackson Harper <jackson@ximian.com>
7 //
8 // Copyright 2003, 2004 Todd Berman
9 // Copyright 2004 Novell, Inc (http://www.novell.com)
13 using System;
14 using System.IO;
15 using System.Diagnostics;
16 using System.Text;
17 using System.Reflection;
18 using System.Collections;
19 using System.Globalization;
20 using System.Runtime.InteropServices;
21 using System.Security.Cryptography;
23 using Mono.Security;
24 using Mono.Security.Cryptography;
26 namespace Mono.Tools {
28 public class Driver {
30 private enum Command {
31 Unknown,
32 Install,
33 InstallFromList,
34 Uninstall,
35 UninstallFromList,
36 UninstallSpecific,
37 List,
38 Help
41 private enum VerificationResult
43 StrongNamed,
44 WeakNamed,
45 DelaySigned,
46 Skipped
49 private static bool silent;
50 static bool in_bootstrap;
52 public static int Main (string [] args)
54 if (args.Length == 0)
55 Usage ();
57 Command command = Command.Unknown;
58 string command_str = null;
60 string libdir;
61 string name, package, gacdir, root;
62 name = package = root = gacdir = null;
63 bool check_refs = false;
65 // Check for silent arg first so we can suppress
66 // warnings during command line parsing
67 if (Array.IndexOf (args, "/silent") > -1 || Array.IndexOf (args, "-silent") > -1)
68 silent = true;
70 for (int i=0; i<args.Length; i++) {
71 if (IsSwitch (args [i])) {
73 // for cmd line compatibility with other gacutils
74 // we always force it though
75 if (args [i] == "-f" || args [i] == "/f")
76 continue;
78 // Ignore this option for now, although we might implement it someday
79 if (args [i] == "/r") {
80 WriteLine ("WARNING: gacutil does not support traced references." +
81 "This option is being ignored.");
82 i += 3;
83 continue;
86 // This is already handled we just dont want to choke on it
87 if (args [i] == "-silent" || args [i] == "/silent")
88 continue;
90 if (args [i] == "-check_refs" || args [i] == "/check_refs") {
91 check_refs = true;
92 continue;
95 if (args [i] == "-bootstrap" || args [i] == "/bootstrap") {
96 in_bootstrap = true;
97 continue;
100 if (command == Command.Unknown) {
101 command = GetCommand (args [i]);
102 if (command != Command.Unknown) {
103 command_str = args [i];
104 continue;
108 if (i + 1 >= args.Length) {
109 Console.WriteLine ("Option " + args [i] + " takes 1 argument");
110 return 1;
113 switch (args [i]) {
114 case "-package":
115 case "/package":
116 package = args [++i];
117 continue;
118 case "-root":
119 case "/root":
120 root = args [++i];
121 continue;
122 case "-gacdir":
123 case "/gacdir":
124 gacdir = args [++i];
125 continue;
126 case "/nologo":
127 case "-nologo":
128 // we currently don't display a
129 // logo banner, so ignore it
130 // for command-line compatibility
131 // with MS gacutil
132 continue;
135 if (name == null)
136 name = args [i];
137 else
138 name += args [i];
141 if (command == Command.Unknown && IsSwitch (args [0])) {
142 Console.WriteLine ("Unknown command: " + args [0]);
143 return 1;
144 } else if (command == Command.Unknown) {
145 Usage ();
146 } else if (command == Command.Help) {
147 ShowHelp (true);
148 return 1;
151 if (gacdir == null) {
152 gacdir = GetGacDir ();
153 libdir = GetLibDir ();
154 } else {
155 gacdir = EnsureLib (gacdir);
156 libdir = Path.Combine (gacdir, "mono");
157 gacdir = Path.Combine (libdir, "gac");
160 string link_gacdir = gacdir;
161 string link_libdir = libdir;
162 if (root != null) {
163 libdir = Path.Combine (root, "mono");
164 gacdir = Path.Combine (libdir, "gac");
167 LoadConfig (silent);
169 switch (command) {
170 case Command.Install:
171 if (name == null) {
172 WriteLine ("Option " + command_str + " takes 1 argument");
173 return 1;
175 if (!Install (check_refs, name, package, gacdir, link_gacdir, libdir, link_libdir))
176 return 1;
177 break;
178 case Command.InstallFromList:
179 if (name == null) {
180 WriteLine ("Option " + command_str + " takes 1 argument");
181 return 1;
183 if (!InstallFromList (check_refs, name, package, gacdir, link_gacdir, libdir, link_libdir))
184 return 1;
185 break;
186 case Command.Uninstall:
187 if (name == null) {
188 WriteLine ("Option " + command_str + " takes 1 argument");
189 return 1;
191 int uninstallCount = 0;
192 int uninstallFailures = 0;
193 Uninstall (name, package, gacdir, libdir, false,
194 ref uninstallCount, ref uninstallFailures);
195 WriteLine ("Assemblies uninstalled = {0}", uninstallCount);
196 WriteLine ("Failures = {0}", uninstallFailures);
197 if (uninstallFailures > 0)
198 return 1;
199 break;
200 case Command.UninstallFromList:
201 if (name == null) {
202 WriteLine ("Option " + command_str + " takes 1 argument");
203 return 1;
205 if (!UninstallFromList (name, package, gacdir, libdir))
206 return 1;
207 break;
208 case Command.UninstallSpecific:
209 if (name == null) {
210 WriteLine ("Option " + command_str + " takes 1 argument");
211 return 1;
213 if (!UninstallSpecific (name, package, gacdir, libdir))
214 return 1;
215 break;
216 case Command.List:
217 List (name, gacdir);
218 break;
221 return 0;
224 static void Copy (string source, string target, bool v)
226 try {
227 File.Delete (target);
228 } catch {}
229 File.Copy (source, target, v);
232 private static bool Install (bool check_refs, string name, string package,
233 string gacdir, string link_gacdir, string libdir, string link_libdir)
235 string failure_msg = "Failure adding assembly {0} to the cache: ";
236 ArrayList resources;
238 if (!File.Exists (name)) {
239 WriteLine (string.Format (failure_msg, name) + "The system cannot find the file specified.");
240 return false;
243 Assembly assembly = null;
244 AssemblyName an = null;
246 try {
247 assembly = Assembly.LoadFrom (name);
248 } catch {
249 WriteLine (string.Format (failure_msg, name) + "The file specified is not a valid assembly.");
250 return false;
253 an = assembly.GetName ();
255 switch (VerifyStrongName (an, name)) {
256 case VerificationResult.StrongNamed:
257 case VerificationResult.Skipped:
258 break;
259 case VerificationResult.WeakNamed:
260 WriteLine (string.Format (failure_msg, name) + "Attempt to install an assembly without a strong name"
261 + (in_bootstrap ? "(continuing anyway)" : string.Empty));
262 if (!in_bootstrap)
263 return false;
264 break;
265 case VerificationResult.DelaySigned:
266 WriteLine (string.Format (failure_msg, name) + "Strong name cannot be verified for delay-signed assembly"
267 + (in_bootstrap ? "(continuing anyway)" : string.Empty));
268 if (!in_bootstrap)
269 return false;
270 break;
273 resources = new ArrayList ();
274 foreach (string res_name in assembly.GetManifestResourceNames ()) {
275 ManifestResourceInfo res_info = assembly.GetManifestResourceInfo (res_name);
277 if ((res_info.ResourceLocation & ResourceLocation.Embedded) == 0) {
278 if (!File.Exists (res_info.FileName)) {
279 WriteLine (string.Format (failure_msg, name) + "The system cannot find resource " + res_info.FileName);
280 return false;
283 resources.Add (res_info);
287 if (check_refs && !CheckReferencedAssemblies (an)) {
288 WriteLine (string.Format (failure_msg, name) +
289 "Attempt to install an assembly that " +
290 "references non strong named assemblies " +
291 "with -check_refs enabled.");
292 return false;
295 string [] siblings = { ".config", ".mdb" };
296 string version_token = an.Version + "_" +
297 an.CultureInfo.Name.ToLower (CultureInfo.InvariantCulture) + "_" +
298 GetStringToken (an.GetPublicKeyToken ());
299 string full_path = Path.Combine (Path.Combine (gacdir, an.Name), version_token);
300 string asmb_file = Path.GetFileName (name);
301 string asmb_path = Path.Combine (full_path, asmb_file);
302 string asmb_name = assembly.GetName ().Name;
304 if (Path.GetFileNameWithoutExtension (asmb_file) != asmb_name) {
305 WriteLine (string.Format (failure_msg, name) +
306 string.Format ("the filename \"{0}\" doesn't match the assembly name \"{1}\"",
307 asmb_file, asmb_name));
308 return false;
311 try {
312 if (Directory.Exists (full_path)) {
313 // Wipe out the directory. This way we ensure old assemblies
314 // config files, and AOTd files are removed.
315 Directory.Delete (full_path, true);
317 Directory.CreateDirectory (full_path);
318 } catch {
319 WriteLine (string.Format (failure_msg, name) +
320 "gac directories could not be created, " +
321 "possibly permission issues.");
322 return false;
325 Copy (name, asmb_path, true);
327 foreach (string ext in siblings) {
328 string sibling = String.Concat (name, ext);
329 if (File.Exists (sibling))
330 Copy (sibling, String.Concat (asmb_path, ext), true);
333 foreach (ManifestResourceInfo resource_info in resources) {
334 try {
335 Copy (resource_info.FileName, Path.Combine (full_path, Path.GetFileName (resource_info.FileName)), true);
336 } catch {
337 WriteLine ("ERROR: Could not install resource file " + resource_info.FileName);
338 Environment.Exit (1);
342 if (package != null) {
343 string ref_dir = Path.Combine (libdir, package);
344 string ref_path = Path.Combine (ref_dir, asmb_file);
346 if (File.Exists (ref_path))
347 File.Delete (ref_path);
348 try {
349 Directory.CreateDirectory (ref_dir);
350 } catch {
351 WriteLine ("ERROR: Could not create package dir file.");
352 Environment.Exit (1);
354 if (Path.DirectorySeparatorChar == '/') {
355 string pkg_path = "../gac/" + an.Name + "/" + version_token + "/" + asmb_file;
356 symlink (pkg_path, ref_path);
358 foreach (string ext in siblings) {
359 string sibling = String.Concat (pkg_path, ext);
360 string sref = String.Concat (ref_path, ext);
361 if (File.Exists (sibling))
362 symlink (sibling, sref);
363 else {
364 try {
365 File.Delete (sref);
366 } catch {
367 // Ignore error, just delete files that should not be there.
371 WriteLine ("Package exported to: {0} -> {1}", ref_path, pkg_path);
372 } else {
373 // string link_path = Path.Combine (Path.Combine (link_gacdir, an.Name), version_token);
375 // We can't use 'link_path' here, since it need not be a valid path at the time 'gacutil'
376 // is run, esp. when invoked in a DESTDIR install.
377 Copy (name, ref_path, true);
378 WriteLine ("Package exported to: " + ref_path);
382 WriteLine ("Installed {0} into the gac ({1})", name,
383 gacdir);
385 return true;
388 private static void Uninstall (string name, string package, string gacdir, string libdir, bool listMode, ref int uninstalled, ref int failures)
390 string [] assembly_pieces = name.Split (new char[] { ',' });
391 Hashtable asm_info = new Hashtable ();
393 foreach (string item in assembly_pieces) {
394 if (item == String.Empty) continue;
395 string[] pieces = item.Trim ().Split (new char[] { '=' }, 2);
396 if(pieces.Length == 1)
397 asm_info ["assembly"] = pieces [0];
398 else
399 asm_info [pieces[0].Trim ().ToLower (CultureInfo.InvariantCulture)] = pieces [1];
402 string assembly_name = (string) asm_info ["assembly"];
403 string asmdir = Path.Combine (gacdir, assembly_name);
404 if (!Directory.Exists (asmdir)) {
405 if (listMode) {
406 failures++;
407 WriteLine ("Assembly: " + name);
409 WriteLine ("No assemblies found that match: " + name);
410 return;
413 string searchString = GetSearchString (asm_info);
414 string [] directories = Directory.GetDirectories (asmdir, searchString);
416 if (directories.Length == 0) {
417 if (listMode) {
418 failures++;
419 WriteLine ("Assembly: " + name);
420 WriteLine ("No assemblies found that match: " + name);
422 return;
425 for (int i = 0; i < directories.Length; i++) {
426 if (listMode && i > 0)
427 break;
429 string dir = directories [i];
431 AssemblyName an = AssemblyName.GetAssemblyName (
432 Path.Combine (dir, assembly_name + ".dll"));
433 WriteLine ("Assembly: " + an.FullName);
435 Directory.Delete (dir, true);
436 if (package != null) {
437 string link_dir = Path.Combine (libdir, package);
438 string link = Path.Combine (link_dir, assembly_name + ".dll");
439 try {
440 File.Delete (link);
441 } catch {
442 // The file might not exist, happens with
443 // the debugger on make uninstall
446 if (Directory.GetFiles (link_dir).Length == 0) {
447 WriteLine ("Cleaning package directory, it is empty.");
448 try {
449 Directory.Delete (link_dir);
450 } catch {
451 // Workaround: GetFiles does not list Symlinks
456 uninstalled++;
457 WriteLine ("Uninstalled: " + an.FullName);
460 if (Directory.GetDirectories (asmdir).Length == 0) {
461 WriteLine ("Cleaning assembly dir, it is empty");
462 try {
463 Directory.Delete (asmdir);
464 } catch {
465 // Workaround: GetFiles does not list Symlinks
470 private static bool UninstallSpecific (string name, string package,
471 string gacdir, string libdir)
473 string failure_msg = "Failure to remove assembly from the cache: ";
475 if (!File.Exists (name)) {
476 WriteLine (failure_msg + "The system cannot find the file specified.");
477 return false;
480 AssemblyName an = null;
482 try {
483 an = AssemblyName.GetAssemblyName (name);
484 } catch {
485 WriteLine (failure_msg + "The file specified is not a valid assembly.");
486 return false;
489 int uninstallCount = 0;
490 int uninstallFailures = 0;
491 Uninstall (an.FullName.Replace (" ", String.Empty),
492 package, gacdir, libdir, true, ref uninstallCount,
493 ref uninstallFailures);
494 WriteLine ("Assemblies uninstalled = {0}", uninstallCount);
495 WriteLine ("Failures = {0}", uninstallFailures);
496 return (uninstallFailures == 0);
499 private static void List (string name, string gacdir)
501 WriteLine ("The following assemblies are installed into the GAC:");
503 if (name != null) {
504 FilteredList (name, gacdir);
505 return;
508 int count = 0;
509 DirectoryInfo gacinfo = new DirectoryInfo (gacdir);
510 foreach (DirectoryInfo parent in gacinfo.GetDirectories ()) {
511 foreach (DirectoryInfo dir in parent.GetDirectories ()) {
512 string asmb = Path.Combine (Path.Combine (parent.FullName, dir.Name), parent.Name) + ".dll";
513 if (File.Exists (asmb)) {
514 WriteLine (AsmbNameFromVersionString (parent.Name, dir.Name));
515 count++;
519 WriteLine ("Number of items = " + count);
522 private static void FilteredList (string name, string gacdir)
524 string [] assembly_pieces = name.Split (new char[] { ',' });
525 Hashtable asm_info = new Hashtable ();
527 foreach (string item in assembly_pieces) {
528 string[] pieces = item.Trim ().Split (new char[] { '=' }, 2);
529 if(pieces.Length == 1)
530 asm_info ["assembly"] = pieces [0];
531 else
532 asm_info [pieces[0].Trim ().ToLower (CultureInfo.InvariantCulture)] = pieces [1];
535 string asmdir = Path.Combine (gacdir, (string) asm_info ["assembly"]);
536 if (!Directory.Exists (asmdir)) {
537 WriteLine ("Number of items = 0");
538 return;
540 string search = GetSearchString (asm_info);
541 string [] dir_list = Directory.GetDirectories (asmdir, search);
543 int count = 0;
544 foreach (string dir in dir_list) {
545 string asmb = Path.Combine (dir, (string) asm_info ["assembly"]) + ".dll";
546 if (File.Exists (asmb)) {
547 WriteLine (AsmbNameFromVersionString ((string) asm_info ["assembly"],
548 new DirectoryInfo (dir).Name));
549 count++;
552 WriteLine ("Number of items = " + count);
555 private static bool InstallFromList (bool check_refs, string list_file, string package,
556 string gacdir, string link_gacdir, string libdir, string link_libdir)
558 StreamReader s = null;
559 int processed, failed;
560 string listdir = Path.GetDirectoryName (
561 Path.GetFullPath (list_file));
563 processed = failed = 0;
565 try {
566 s = new StreamReader (list_file);
568 string line;
569 while ((line = s.ReadLine ()) != null) {
570 string file = line.Trim ();
571 if (file.Length == 0)
572 continue;
574 string assemblyPath = Path.Combine (listdir,
575 file);
577 if (!Install (check_refs, assemblyPath, package, gacdir,
578 link_gacdir, libdir, link_libdir))
579 failed++;
580 processed++;
583 WriteLine ("Assemblies processed = {0}", processed);
584 WriteLine ("Assemblies installed = {0}", processed - failed);
585 WriteLine ("Failures = {0}", failed);
587 return (failed == 0);
588 } catch (IOException) {
589 WriteLine ("Failed to open assemblies list file " + list_file + ".");
590 return false;
591 } finally {
592 if (s != null)
593 s.Close ();
597 private static bool UninstallFromList (string list_file, string package,
598 string gacdir, string libdir)
600 StreamReader s = null;
601 int failed, uninstalled;
603 failed = uninstalled = 0;
605 try {
606 s = new StreamReader (list_file);
608 string line;
609 while ((line = s.ReadLine ()) != null) {
610 string name = line.Trim ();
611 if (name.Length == 0)
612 continue;
613 Uninstall (line, package, gacdir, libdir,
614 true, ref uninstalled, ref failed);
617 WriteLine ("Assemblies processed = {0}", uninstalled+failed);
618 WriteLine ("Assemblies uninstalled = {0}", uninstalled);
619 WriteLine ("Failures = {0}", failed);
621 return (failed == 0);
622 } catch (IOException) {
623 WriteLine ("Failed to open assemblies list file " + list_file + ".");
624 return false;
625 } finally {
626 if (s != null)
627 s.Close ();
631 private static bool CheckReferencedAssemblies (AssemblyName an)
633 AppDomain d = null;
634 try {
635 Assembly a = Assembly.LoadFrom (an.CodeBase);
636 AssemblyName corlib = typeof (object).Assembly.GetName ();
638 foreach (AssemblyName ref_an in a.GetReferencedAssemblies ()) {
639 if (ref_an.Name == corlib.Name) // Just do a string compare so we can install on diff versions
640 continue;
641 byte [] pt = ref_an.GetPublicKeyToken ();
642 if (pt == null || pt.Length == 0) {
643 WriteLine ("Assembly " + ref_an.Name + " is not strong named.");
644 return false;
647 } catch (Exception e) {
648 WriteLine (e.ToString ()); // This should be removed pre beta3
649 return false;
650 } finally {
651 if (d != null) {
652 try {
653 AppDomain.Unload (d);
654 } catch { }
658 return true;
661 private static string GetSearchString (Hashtable asm_info)
663 if (asm_info.Keys.Count == 1)
664 return "*";
665 string version, culture, token;
667 version = asm_info ["version"] as string;
668 version = (version == null ? "*" : version + "*");
669 culture = asm_info ["culture"] as string;
670 culture = (culture == null ? "*" : (culture == "neutral") ? String.Empty : culture.ToLower (CultureInfo.InvariantCulture));
671 token = asm_info ["publickeytoken"] as string;
672 token = (token == null ? "*" : token.ToLower (CultureInfo.InvariantCulture));
674 return String.Format ("{0}_{1}_{2}", version, culture, token);
677 private static string AsmbNameFromVersionString (string name, string str)
679 string [] pieces = str.Split ('_');
680 return String.Format ("{0}, Version={1}, Culture={2}, PublicKeyToken={3}",
681 name, pieces [0], (pieces [1] == String.Empty ? "neutral" : pieces [1]),
682 pieces [2]);
685 static bool LoadConfig (bool quiet)
687 MethodInfo config = typeof (System.Environment).GetMethod ("GetMachineConfigPath",
688 BindingFlags.Static | BindingFlags.NonPublic);
690 if (config != null) {
691 string path = (string) config.Invoke (null, null);
693 bool exist = File.Exists (path);
694 if (!quiet && !exist)
695 Console.WriteLine ("Couldn't find machine.config");
697 StrongNameManager.LoadConfig (path);
698 return exist;
699 } else if (!quiet)
700 Console.WriteLine ("Couldn't resolve machine.config location (corlib issue)");
702 // default CSP
703 return false;
706 // modified copy from sn
707 private static VerificationResult VerifyStrongName (AssemblyName an, string assemblyFile)
709 byte [] publicKey = StrongNameManager.GetMappedPublicKey (an.GetPublicKeyToken ());
710 if ((publicKey == null) || (publicKey.Length < 12)) {
711 // no mapping
712 publicKey = an.GetPublicKey ();
713 if ((publicKey == null) || (publicKey.Length < 12))
714 return VerificationResult.WeakNamed;
717 // Note: MustVerify is based on the original token (by design). Public key
718 // remapping won't affect if the assembly is verified or not.
719 if (StrongNameManager.MustVerify (an)) {
720 RSA rsa = CryptoConvert.FromCapiPublicKeyBlob (publicKey, 12);
721 StrongName sn = new StrongName (rsa);
722 if (sn.Verify (assemblyFile)) {
723 return VerificationResult.StrongNamed;
724 } else {
725 return VerificationResult.DelaySigned;
727 } else {
728 return VerificationResult.Skipped;
732 private static bool IsSwitch (string arg)
734 return (arg [0] == '-' || (arg [0] == '/' && !arg.EndsWith(".dll") && arg.IndexOf('/', 1) < 0 ) );
737 private static Command GetCommand (string arg)
739 Command c = Command.Unknown;
741 switch (arg) {
742 case "-i":
743 case "/i":
744 case "--install":
745 c = Command.Install;
746 break;
747 case "-il":
748 case "/il":
749 case "--install-from-list":
750 c = Command.InstallFromList;
751 break;
752 case "-u":
753 case "/u":
754 case "/uf":
755 case "--uninstall":
756 c = Command.Uninstall;
757 break;
758 case "-ul":
759 case "/ul":
760 case "--uninstall-from-list":
761 c = Command.UninstallFromList;
762 break;
763 case "-us":
764 case "/us":
765 case "--uninstall-specific":
766 c = Command.UninstallSpecific;
767 break;
768 case "-l":
769 case "/l":
770 case "--list":
771 c = Command.List;
772 break;
773 case "-?":
774 case "/?":
775 case "--help":
776 c = Command.Help;
777 break;
779 return c;
782 [DllImport ("libc", SetLastError=true)]
783 public static extern int symlink (string oldpath, string newpath);
785 private static string GetGacDir () {
786 PropertyInfo gac = typeof (System.Environment).GetProperty ("GacPath",
787 BindingFlags.Static|BindingFlags.NonPublic);
788 if (gac == null) {
789 WriteLine ("ERROR: Mono runtime not detected, please use " +
790 "the mono runtime for gacutil.exe");
791 Environment.Exit (1);
793 MethodInfo get_gac = gac.GetGetMethod (true);
794 return (string) get_gac.Invoke (null, null);
797 private static string GetLibDir () {
798 MethodInfo libdir = typeof (System.Environment).GetMethod ("internalGetGacPath",
799 BindingFlags.Static|BindingFlags.NonPublic);
800 if (libdir == null) {
801 WriteLine ("ERROR: Mono runtime not detected, please use " +
802 "the mono runtime for gacutil.exe");
803 Environment.Exit (1);
805 return Path.Combine ((string)libdir.Invoke (null, null), "mono");
808 private static string GetStringToken (byte[] tok)
810 StringBuilder sb = new StringBuilder ();
811 for (int i = 0; i < tok.Length ; i++)
812 sb.Append (tok[i].ToString ("x2"));
813 return sb.ToString ();
816 private static string EnsureLib (string dir)
818 DirectoryInfo d = new DirectoryInfo (dir);
819 if (d.Name == "lib")
820 return dir;
821 return Path.Combine (dir, "lib");
824 private static void WriteLine ()
826 if (silent)
827 return;
828 Console.WriteLine ();
831 private static void WriteLine (string line)
833 if (silent)
834 return;
835 Console.WriteLine (line);
838 private static void WriteLine (string line, params object [] p)
840 if (silent)
841 return;
842 Console.WriteLine (line, p);
845 private static void Usage ()
847 ShowHelp (false);
848 Environment.Exit (1);
851 private static void ShowHelp (bool detailed)
853 WriteLine ("Usage: gacutil.exe <commands> [ <options> ]");
854 WriteLine ("Commands:");
856 WriteLine ("-i <assembly_path> [-check_refs] [-package NAME] [-root ROOTDIR] [-gacdir GACDIR]");
857 WriteLine ("\tInstalls an assembly into the global assembly cache.");
858 if (detailed) {
859 WriteLine ("\t<assembly_path> is the name of the file that contains the " +
860 "\tassembly manifest\n" +
861 "\tExample: -i myDll.dll");
863 WriteLine ();
865 WriteLine ("-il <assembly_list_file> [-check_refs] [-package NAME] [-root ROOTDIR] [-gacdir GACDIR]");
866 WriteLine ("\tInstalls one or more assemblies into the global assembly cache.");
867 if (detailed) {
868 WriteLine ("\t<assembly_list_file> is the path to a test file containing a list of\n" +
869 "\tassembly file paths on separate lines.\n" +
870 "\tExample -il assembly_list.txt\n" +
871 "\t\tassembly_list.txt contents:\n" +
872 "\t\tassembly1.dll\n" +
873 "\t\tassembly2.dll");
875 WriteLine ();
877 WriteLine ("-u <assembly_display_name> [-package NAME] [-root ROOTDIR] [-gacdir GACDIR]");
878 WriteLine ("\tUninstalls an assembly from the global assembly cache.");
879 if (detailed) {
880 WriteLine ("\t<assembly_display_name> is the name of the assembly (partial or\n" +
881 "\tfully qualified) to remove from the global assembly cache. If a \n" +
882 "\tpartial name is specified all matching assemblies will be uninstalled.\n" +
883 "\tExample: -u myDll,Version=1.2.1.0");
885 WriteLine ();
887 WriteLine ("-ul <assembly_list_file> [-package NAME] [-root ROOTDIR] [-gacdir GACDIR]");
888 WriteLine ("\tUninstalls one or more assemblies from the global assembly cache.");
889 if (detailed) {
890 WriteLine ("\t<assembly_list_file> is the path to a test file containing a list of\n" +
891 "\tassembly names on separate lines.\n" +
892 "\tExample -ul assembly_list.txt\n" +
893 "\t\tassembly_list.txt contents:\n" +
894 "\t\tassembly1,Version=1.0.0.0,Culture=en,PublicKeyToken=0123456789abcdef\n" +
895 "\t\tassembly2,Version=2.0.0.0,Culture=en,PublicKeyToken=0123456789abcdef");
897 WriteLine ();
899 WriteLine ("-us <assembly_path> [-package NAME] [-root ROOTDIR] [-gacdir GACDIR]");
900 WriteLine ("\tUninstalls an assembly using the specifed assemblies full name.");
901 if (detailed) {
902 WriteLine ("\t<assembly path> is the path to an assembly. The full assembly name\n" +
903 "\tis retrieved from the specified assembly if there is an assembly in\n" +
904 "\tthe GAC with a matching name, it is removed.\n" +
905 "\tExample: -us myDll.dll");
907 WriteLine ();
909 WriteLine ("-l [assembly_name] [-root ROOTDIR] [-gacdir GACDIR]");
910 WriteLine ("\tLists the contents of the global assembly cache.");
911 if (detailed) {
912 WriteLine ("\tWhen the <assembly_name> parameter is specified only matching\n" +
913 "\tassemblies are listed.");
915 WriteLine ();
917 WriteLine ("-?");
918 WriteLine ("\tDisplays a detailed help screen");
919 WriteLine ();
921 if (!detailed)
922 return;
924 WriteLine ("Options:");
925 WriteLine ("-package <NAME>");
926 WriteLine ("\tUsed to create a directory in prefix/lib/mono with the name NAME, and a\n" +
927 "\tsymlink is created from NAME/assembly_name to the assembly on the GAC.\n" +
928 "\tThis is used so developers can reference a set of libraries at once.");
929 WriteLine ();
931 WriteLine ("-gacdir <GACDIR>");
932 WriteLine ("\tUsed to specify the GACs base directory. Once an assembly has been installed\n" +
933 "\tto a non standard gacdir the MONO_GAC_PREFIX environment variable must be used\n" +
934 "\tto access the assembly.");
935 WriteLine ();
937 WriteLine ("-root <ROOTDIR>");
938 WriteLine ("\tUsed by developers integrating this with automake tools or packaging tools\n" +
939 "\tthat require a prefix directory to be specified. The root represents the\n" +
940 "\t\"libdir\" component of a prefix (typically prefix/lib).");
941 WriteLine ();
943 WriteLine ("-check_refs");
944 WriteLine ("\tUsed to ensure that the assembly being installed into the GAC does not\n" +
945 "\treference any non strong named assemblies. Assemblies being installed to\n" +
946 "\tthe GAC should not reference non strong named assemblies, however the is\n" +
947 "\tan optional check.");
949 WriteLine ();
950 WriteLine ("Ignored Options:");
951 WriteLine ("-f");
952 WriteLine ("\tThe Mono gacutil ignores the -f option to maintain commandline compatibility with");
953 WriteLine ("\tother gacutils. gacutil will always force the installation of a new assembly.");
955 WriteLine ();
956 WriteLine ("-r <reference_scheme> <reference_id> <description>");
957 WriteLine ("\tThe Mono gacutil has not implemented traced references and will emit a warning");
958 WriteLine ("\twhen this option is used.");