Ejemplo n.º 1
0
        public static string ToILmergeTargetPlatform(string version, string architecture)
        {
            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentNullException(nameof(version));
            }

            string path;
            TargetDotNetFrameworkVersion fversion;
            DotNetFrameworkArchitecture  farchitecture;

            if (!FrameworkInfo.TryParseVersion(version, out fversion))
            {
                throw new ArgumentOutOfRangeException(nameof(version), $"Unable to parse .Net framework version: {version}");
            }

            if (string.IsNullOrWhiteSpace(architecture))
            {
                path = FrameworkInfo.GetPathToDotNetFramework(fversion);
            }
            else
            {
                if (FrameworkInfo.TryParsePlatform(architecture, out farchitecture))
                {
                    path = FrameworkInfo.GetPathToDotNetFramework(fversion, farchitecture);
                }
                else
                {
                    path = FrameworkInfo.GetPathToDotNetFramework(fversion);
                }
            }

            if (string.IsNullOrWhiteSpace(path))
            {
                throw new Exception($"Unable to resolve .Net Framework directory. Framework version: {version}");
            }

            return($"{VersionToString(fversion)},{path}");
        }
        private void SetDefaults(MergerSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.General == null)
            {
                settings.General = new GeneralSettings();
            }

            if (!settings.General.KeyFile.HasValue() && this.KeyFile.HasValue())
            {
                settings.General.KeyFile = ToAbsolutePath(KeyFile);
                Log.LogMessage("Applying default value for KeyFile.");
            }

            if (!settings.General.OutputFile.HasValue())
            {
                settings.General.OutputFile = Path.Combine(this.TargetDir, "ILMerge", this.TargetFileName);
                Log.LogMessage("Applying default value for OutputFile.");
            }

            if (!settings.General.TargetPlatform.HasValue())
            {
                settings.General.TargetPlatform = FrameworkInfo.ToILmergeTargetPlatform(this.TargetFrameworkVersion, this.TargetArchitecture);
                Log.LogMessage($"Applying default value for TargetPlatform: {settings.General.TargetPlatform}");
            }

            if (settings.General.InputAssemblies == null || settings.General.InputAssemblies.Count == 0)
            {
                Log.LogMessage("No input assembles were found in configuration.");

                settings.General.InputAssemblies = new List <string>();

                Log.LogMessage($"Adding target assembly: {this.TargetPath}");
                settings.General.InputAssemblies.Add(this.TargetPath);

                foreach (var item in this.InputAssemblies)
                {
                    Log.LogMessage($"Adding assembly: {item.ItemSpec}");
                    settings.General.InputAssemblies.Add(item.ItemSpec);
                }
            }
            else
            {
                foreach (var item in settings.General.InputAssemblies)
                {
                    Log.LogMessage($"Config input assembly: {item}");
                }

                Log.LogMessage($"Adding target assembly at position [0]: {this.TargetPath}");
                settings.General.InputAssemblies.Insert(0, this.TargetPath);
            }

            if (settings.Advanced == null)
            {
                settings.Advanced = new AdvancedSettings();
            }

            if (settings.Advanced.SearchDirectories == null)
            {
                settings.Advanced.SearchDirectories = new List <string>();
            }

            if (!settings.Advanced.SearchDirectories.Contains(this.TargetDir))
            {
                settings.Advanced.SearchDirectories.Add(this.TargetDir);
            }

            if (this.AdditionalLocations != null && this.AdditionalLocations.Any())
            {
                foreach (var dir in this.AdditionalLocations)
                {
                    if (!settings.Advanced.SearchDirectories.Contains(dir))
                    {
                        settings.Advanced.SearchDirectories.Add(dir);
                    }
                }
            }
        }