internal static Int32 Main(String[] args) { ExitCode retVal; SimpleApplicationParameters paramInstance = null; try { var paramModel = new SimpleApplicationParametersModel( "Files", new StringOptionModel("help", "?"), new StringOptionModel(OUT), new OptionModel[] { new StringOptionModel(KEY_FILE), new EnumOptionModel <AssemblyHashAlgorithm>(SIGN_ALGORITHM, true), new StringOptionModel(LOG), new ListOptionModel(VER, new OptionModel(typeof(UInt16), null), ".", 4, 4), new SwitchOptionModel(UNION), new SwitchOptionModel(NODEBUG), new SwitchOptionModel(COPY_ATTRS), new StringOptionModel(ATTR), new SwitchOptionModel(ALLOW_MULTIPLE), new EnumOptionModel <ModuleKind>(TARGET, true), new StringOptionModel(TARGET_PLATFORM), new SwitchOptionModel(XML_DOCS), new StringOptionModel(LIB), new StringOptionModel(INTERNALIZE), new SwitchOptionModel(DELAY_SIGN), new SwitchOptionModel(USE_FULL_PUBLIC_KEY_FOR_REFERENCES), new OptionModel(typeof(Int32), ALIGN), new SwitchOptionModel(CLOSED), new StringOptionModel(ALLOW_DUP), new SwitchOptionModel(ALLOW_DUP_RES), new SwitchOptionModel(ZERO_PE_KIND), new SwitchOptionModel(PARALLEL), new SwitchOptionModel(PAUSE), new SwitchOptionModel(VERBOSE), new SwitchOptionModel(WILDCARDS), new StringOptionModel(SUBSYSTEMVERSION, new System.Text.RegularExpressions.Regex(@"\d{1,5}\.\d{1,5}")), new SwitchOptionModel(HIGH_ENTROPY_VA) }, 1, LIB, ALLOW_DUP ); paramInstance = new SimpleApplicationParameters(paramModel, args); if (paramInstance.Errors.Count > 0) { Console.Error.WriteLine("Errors in command-line arguments:\n" + String.Join("\n", paramInstance.Errors)); retVal = ExitCode.ExceptionDuringStartup; } else if (paramInstance.HelpOptionPresent) { Console.WriteLine("TODO Help."); retVal = ExitCode.Success; } else { var options = FromApplicationOptions(paramInstance); #if DEBUG options.DoLogging = true; options.CILLogCallback = new CILMergeLogCallbackImpl(); #endif var merger = new CILMerger(options); merger.PerformMerge(); retVal = ExitCode.Success; } } catch (CILMergeException cExc) { retVal = cExc._exitCode; Console.Error.WriteLine("Error: " + cExc.Message); } catch (Exception exc) { Console.Error.WriteLine("An exception occurred:\n" + exc); retVal = ExitCode.ExceptionDuringMerge; } if (paramInstance != null && paramInstance.GetSingleOptionOrNull(PAUSE).GetOrDefault(false)) { Console.ReadKey(); } return((Int32)retVal); }
private static CILMergeOptionsImpl FromApplicationOptions(SimpleApplicationParameters args) { var options = new CILMergeOptionsImpl(); options.OutPath = args.SeparatorOption.OptionValueAsString; options.KeyFile = args.GetSingleOptionOrNull(KEY_FILE).GetOrDefault <String>(); options.SigningAlgorithm = args.GetSingleOptionOrNull(SIGN_ALGORITHM).GetOrDefault <AssemblyHashAlgorithm?>(); var logOption = args.GetSingleOptionOrNull(LOG); options.DoLogging = logOption != null; if (options.DoLogging && !String.IsNullOrEmpty(logOption.OptionValueAsString)) { options.LogFile = logOption.OptionValueAsString; } var ver = args.GetSingleOptionOrNull(VER).GetOrDefault <List <UInt16> >(); if (ver != null) { options.VerMajor = ver[0]; options.VerMinor = ver[1]; options.VerBuild = ver[2]; options.VerRevision = ver[3]; } else { options.VerMajor = options.VerMinor = options.VerBuild = options.VerRevision = -1; } options.Union = args.GetSingleOptionOrNull(UNION).GetOrDefault(false); options.NoDebug = args.GetSingleOptionOrNull(NODEBUG).GetOrDefault(false); options.CopyAttributes = args.GetSingleOptionOrNull(COPY_ATTRS).GetOrDefault(false); options.AttrSource = args.GetSingleOptionOrNull(ATTR).GetOrDefault <String>(); options.AllowMultipleAssemblyAttributes = args.GetSingleOptionOrNull(ALLOW_MULTIPLE).GetOrDefault(false); options.Target = args.GetSingleOptionOrNull(TARGET).GetOrDefault <ModuleKind?>(); var tp = args.GetSingleOptionOrNull(TARGET_PLATFORM).GetOrDefault <String>(); if (tp != null) { var idx = tp.IndexOf(","); var trString = idx == -1 ? tp : tp.Substring(0, idx); switch (trString) { case "v1": options.TargetPlatform = TargetRuntime.Net_1_0; break; case "v1.1": options.TargetPlatform = TargetRuntime.Net_1_1; break; case "v2": options.TargetPlatform = TargetRuntime.Net_2_0; break; case "v4": options.TargetPlatform = TargetRuntime.Net_4_0; break; default: TargetRuntime tr; if (Enum.TryParse(trString, true, out tr)) { options.TargetPlatform = tr; } break; } } options.XmlDocs = args.GetSingleOptionOrNull(XML_DOCS).GetOrDefault(false); options.LibPaths = args.GetMultipleOptionsOrEmpty(LIB).Select(o => o.OptionValueAsString).ToArray(); var internalizeOption = args.GetSingleOptionOrNull(INTERNALIZE); options.Internalize = internalizeOption != null; if (options.Internalize && !String.IsNullOrEmpty(internalizeOption.OptionValueAsString)) { options.ExcludeFile = internalizeOption.OptionValueAsString; } options.DelaySign = args.GetSingleOptionOrNull(DELAY_SIGN).GetOrDefault(false); options.UseFullPublicKeyForRefs = args.GetSingleOptionOrNull(USE_FULL_PUBLIC_KEY_FOR_REFERENCES).GetOrDefault(false); options.Align = args.GetSingleOptionOrNull(ALIGN).GetOrDefault(MIN_FILE_ALIGN); options.Closed = args.GetSingleOptionOrNull(CLOSED).GetOrDefault(false); var dups = args.GetMultipleOptionsOrEmpty(ALLOW_DUP); options.AllowDuplicateTypes = dups.Count > 0 ? (dups.Any(d => String.IsNullOrEmpty(d.OptionValueAsString)) ? null : new HashSet <String>(dups.Where(d => !String.IsNullOrEmpty(d.OptionValueAsString)).Select(d => d.OptionValueAsString).ToArray())) : new HashSet <String>(); options.AllowDuplicateResources = args.GetSingleOptionOrNull(ALLOW_DUP_RES).GetOrDefault(false); options.ZeroPEKind = args.GetSingleOptionOrNull(ZERO_PE_KIND).GetOrDefault(false); options.Parallel = args.GetSingleOptionOrNull(PARALLEL).GetOrDefault(false); options.Verbose = args.GetSingleOptionOrNull(VERBOSE).GetOrDefault(false); options.InputAssemblies = args.Values.Distinct().ToArray(); options.AllowWildCards = args.GetSingleOptionOrNull(WILDCARDS).GetOrDefault <Boolean>(); options.OutPath = RootPath(options.OutPath); if (!options.AllowWildCards) { for (var i = 0; i < options.InputAssemblies.Length; ++i) { options.InputAssemblies[i] = RootPath(options.InputAssemblies[i]); } } options.KeyFile = RootPath(options.KeyFile); options.AttrSource = RootPath(options.AttrSource); options.ExcludeFile = RootPath(options.ExcludeFile); var subSysStr = args.GetSingleOptionOrNull(SUBSYSTEMVERSION).GetOrDefault("4.0"); var sep = subSysStr.IndexOf('.'); options.SubsystemMajor = Int32.Parse(subSysStr.Substring(0, sep)); options.SubsystemMinor = Int32.Parse(subSysStr.Substring(sep + 1)); options.HighEntropyVA = args.GetSingleOptionOrNull(HIGH_ENTROPY_VA).GetOrDefault(false); return(options); }