Resolve() public method

public Resolve ( Mono.Cecil.AssemblyNameReference name ) : AssemblyDefinition
name Mono.Cecil.AssemblyNameReference
return AssemblyDefinition
コード例 #1
0
		public static string GenerateBlackList(string librariesFolder, RuntimeClassRegistry usedClasses, string[] allAssemblies)
		{
			string text = "tmplink.xml";
			usedClasses.SynchronizeClasses();
			using (TextWriter textWriter = new StreamWriter(Path.Combine(librariesFolder, text)))
			{
				textWriter.WriteLine("<linker>");
				textWriter.WriteLine("<assembly fullname=\"UnityEngine\">");
				foreach (string current in usedClasses.GetAllManagedClassesAsString())
				{
					textWriter.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", current, usedClasses.GetRetentionLevel(current)));
				}
				textWriter.WriteLine("</assembly>");
				DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver();
				defaultAssemblyResolver.AddSearchDirectory(librariesFolder);
				for (int i = 0; i < allAssemblies.Length; i++)
				{
					string path = allAssemblies[i];
					AssemblyDefinition assemblyDefinition = defaultAssemblyResolver.Resolve(Path.GetFileNameWithoutExtension(path), new ReaderParameters
					{
						AssemblyResolver = defaultAssemblyResolver
					});
					textWriter.WriteLine("<assembly fullname=\"{0}\">", assemblyDefinition.Name.Name);
					MonoAssemblyStripping.GenerateBlackListTypeXML(textWriter, assemblyDefinition.MainModule.Types, usedClasses.GetAllManagedBaseClassesAsString());
					textWriter.WriteLine("</assembly>");
				}
				textWriter.WriteLine("</linker>");
			}
			return text;
		}
コード例 #2
0
ファイル: Program.cs プロジェクト: AlexFRAN/duplicati
		//Adapted from: https://stackoverflow.com/questions/9262464/tool-to-show-assembly-dependencies
		public static void PoC(IEnumerable<AssemblyDefinition> assemblies, TextWriter writer, IEnumerable<string> searchfolders)
		{
			var resolver = new DefaultAssemblyResolver();
			searchfolders.ToList().ForEach(x => resolver.AddSearchDirectory(x));

			//writer.WriteLine("digraph Dependencies {");
			var loaded = assemblies
				.SelectMany(a => a.Modules.Cast<ModuleDefinition>())
				.SelectMany(m => m.AssemblyReferences.Cast<AssemblyNameReference>())
				.Distinct()
				.Select(asm => {
					var dllname = asm.Name + ".dll";
					//Console.WriteLine("Probing for {0}", dllname);
					try { return AssemblyDefinition.ReadAssembly(dllname); }
					catch { } 
					try { return resolver.Resolve(asm.FullName); }
					catch { }

					return null;
				})
				.Where(assembly => assembly != null)
				.ToList();

			//loaded.ForEach(a => a.MainModule.ReadSymbols());

			loaded.Select(x => x.FullName).Distinct().OrderBy(x => x).ToList().ForEach(x => writer.WriteLine("{0}", x));
			/*loaded.ForEach(a =>
				{
					foreach (var r in a.MainModule.AssemblyReferences.Cast<AssemblyNameReference>())
						writer.WriteLine(@"""{0}"" -> ""{1}"";", r.Name, a.Name.Name);
				} );*/

			//writer.WriteLine("}");
		}
コード例 #3
0
        private static ModuleDefinition ResolveInterceptorModuleDefinition()
        {
            const string InterceptorAssemblyName = "StaticProxy.Interceptor";

            AssemblyDefinition definition = ModuleWeaver.Instance.AssemblyResolver.Resolve(InterceptorAssemblyName);
            if (definition == null)
            {
                // todo use an integration test to test this!
                DirectoryInfo nugetPackagesDirectory = Directory.GetParent(ModuleWeaver.Instance.AddinDirectoryPath);
                var assemblyResolver = new DefaultAssemblyResolver();

                DirectoryInfo[] packageDirectores = nugetPackagesDirectory.GetDirectories();
                foreach (DirectoryInfo packageDirectory in packageDirectores)
                {
                    assemblyResolver.AddSearchDirectory(packageDirectory.FullName);
                }

                definition = assemblyResolver.Resolve(InterceptorAssemblyName);
                if (definition == null)
                {
                    throw new WeavingException("Can't find StaticProxy.Interceptor assembly. Make sure you've downloaded and installed the nuget package!");
                }
            }

            return definition.MainModule;
        }
コード例 #4
0
 public static string GenerateBlackList(string librariesFolder, RuntimeClassRegistry usedClasses, string[] allAssemblies)
 {
     string str = "tmplink.xml";
     usedClasses.SynchronizeClasses();
     using (TextWriter writer = new StreamWriter(Path.Combine(librariesFolder, str)))
     {
         writer.WriteLine("<linker>");
         writer.WriteLine("<assembly fullname=\"UnityEngine\">");
         foreach (string str2 in usedClasses.GetAllManagedClassesAsString())
         {
             writer.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", str2, usedClasses.GetRetentionLevel(str2)));
         }
         writer.WriteLine("</assembly>");
         DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();
         resolver.AddSearchDirectory(librariesFolder);
         foreach (string str3 in allAssemblies)
         {
             ReaderParameters parameters = new ReaderParameters {
                 AssemblyResolver = resolver
             };
             AssemblyDefinition definition = resolver.Resolve(Path.GetFileNameWithoutExtension(str3), parameters);
             writer.WriteLine("<assembly fullname=\"{0}\">", definition.Name.Name);
             if (definition.Name.Name.StartsWith("UnityEngine."))
             {
                 foreach (string str4 in usedClasses.GetAllManagedClassesAsString())
                 {
                     writer.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", str4, usedClasses.GetRetentionLevel(str4)));
                 }
             }
             GenerateBlackListTypeXML(writer, definition.MainModule.Types, usedClasses.GetAllManagedBaseClassesAsString());
             writer.WriteLine("</assembly>");
         }
         writer.WriteLine("</linker>");
     }
     return str;
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: simon-heinen/JSIL
        static Configuration ParseCommandLine(
            IEnumerable<string> arguments, List<BuildGroup> buildGroups, 
            Dictionary<string, IProfile> profiles
        )
        {
            var baseConfig = new Configuration();
            var commandLineConfig = new Configuration();
            IProfile defaultProfile = new Profiles.Default();
            var profileAssemblies = new List<string>();
            bool[] autoloadProfiles = new bool[] { true };
            string[] newDefaultProfile = new string[] { null };
            List<string> filenames;

            {
                var os = new Mono.Options.OptionSet {
                    {"o=|out=",
                        "Specifies the output directory for generated javascript and manifests.",
                        (path) => commandLineConfig.OutputDirectory = Path.GetFullPath(path) },
                    {"nac|noautoconfig",
                        "Suppresses automatic loading of same-named .jsilconfig files located next to solutions and/or assemblies.",
                        (b) => commandLineConfig.AutoLoadConfigFiles = b == null },
                    {"nt|nothreads",
                        "Suppresses use of multiple threads to speed up the translation process.",
                        (b) => commandLineConfig.UseThreads = b == null },
                    {"sbc|suppressbugcheck",
                        "Suppresses JSIL bug checks that detect bugs in .NET runtimes and standard libraries.",
                        (b) => commandLineConfig.RunBugChecks = b == null },

                    "Solution Builder options",
                    {"configuration=",
                        "When building one or more solution files, specifies the build configuration to use (like 'Debug').",
                        (v) => commandLineConfig.SolutionBuilder.Configuration = v },
                    {"platform=",
                        "When building one or more solution files, specifies the build platform to use (like 'x86').",
                        (v) => commandLineConfig.SolutionBuilder.Platform = v },
                    {"target=",
                        "When building one or more solution files, specifies the build target to use (like 'Build'). The default is 'Build'.",
                        (v) => commandLineConfig.SolutionBuilder.Target = v },
                    {"logVerbosity=",
                        "When building one or more solution files, specifies the level of log verbosity. Valid options are 'Quiet', 'Minimal', 'Normal', 'Detailed', and 'Diagnostic'.",
                        (v) => commandLineConfig.SolutionBuilder.LogVerbosity = v },

                    "Assembly options",
                    {"p=|proxy=",
                        "Loads a type proxy assembly to provide type information for the translator.",
                        (name) => commandLineConfig.Assemblies.Proxies.Add(Path.GetFullPath(name)) },
                    {"i=|ignore=",
                        "Specifies a regular expression pattern for assembly names that should be ignored during the translation process.",
                        (regex) => commandLineConfig.Assemblies.Ignored.Add(regex) },
                    {"s=|stub=",
                        "Specifies a regular expression pattern for assembly names that should be stubbed during the translation process. " +
                        "Stubbing forces all methods to be externals.",
                        (regex) => commandLineConfig.Assemblies.Stubbed.Add(regex) },
                    {"nd|nodeps",
                        "Suppresses the automatic loading and translation of assembly dependencies.",
                        (b) => commandLineConfig.IncludeDependencies = b == null},
                    {"nodefaults",
                        "Suppresses the default list of stubbed assemblies.",
                        (b) => commandLineConfig.ApplyDefaults = b == null},
                    {"nolocal",
                        "Disables using local proxy types from translated assemblies.",
                        (b) => commandLineConfig.UseLocalProxies = b == null},
                    {"fv=|frameworkVersion=",
                        "Specifies the version of the .NET framework proxies to use. " +
                        "This ensures that correct type information is provided (as different versions of the framework use different standard libraries). " +
                        "The only accepted value is currently '4.0'. Default: '4.0'",
                        (fv) => commandLineConfig.FrameworkVersion = double.Parse(fv)},

                    "Profile options",
                    {"nap|noautoloadprofiles",
                        "Disables automatic loading of profile assemblies from the compiler directory.",
                        (b) => autoloadProfiles[0] = (b == null)},
                    {"pa=|profileAssembly=",
                        "Loads one or more project profiles from the specified profile assembly. Note that this does not force the profiles to be used.",
                        (filename) => profileAssemblies.Add(filename)},
                    {"dp=|defaultProfile=",
                        "Overrides the default profile to use for projects by specifying the name of the new default profile.",
                        (profileName) => newDefaultProfile[0] = profileName},

                    "CodeGenerator options",
                    {"os",
                        "Suppresses struct copy elimination.",
                        (b) => commandLineConfig.CodeGenerator.EliminateStructCopies = b == null},
                    {"ot",
                        "Suppresses temporary local variable elimination.",
                        (b) => commandLineConfig.CodeGenerator.EliminateTemporaries = b == null},
                    {"oo",
                        "Suppresses simplification of operator expressions and special method calls.",
                        (b) => commandLineConfig.CodeGenerator.SimplifyOperators = b == null},
                    {"ol",
                        "Suppresses simplification of loop blocks.",
                        (b) => commandLineConfig.CodeGenerator.SimplifyLoops = b == null},
                };

                filenames = os.Parse(arguments);

                if (filenames.Count == 0) {
                    var asmName = Assembly.GetExecutingAssembly().GetName();
                    Console.WriteLine("==== JSILc v{0}.{1}.{2} ====", asmName.Version.Major, asmName.Version.Minor, asmName.Version.Revision);
                    Console.WriteLine("Specify one or more compiled assemblies (dll/exe) to translate them. Symbols will be loaded if they exist in the same directory.");
                    Console.WriteLine("You can also specify Visual Studio solution files (sln) to build them and automatically translate their output(s).");
                    Console.WriteLine("Specify the path of a .jsilconfig file to load settings from it.");

                    os.WriteOptionDescriptions(Console.Out);

                    return null;
                }
            }

            {
                if (autoloadProfiles[0])
                    profileAssemblies.AddRange(Directory.GetFiles(
                        GetJSILDirectory(),
                        "JSIL.Profiles.*.dll"
                    ));

                foreach (var filename in profileAssemblies) {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        var assembly = Assembly.LoadFile(fullPath);

                        foreach (var type in assembly.GetTypes()) {
                            if (
                                type.FindInterfaces(
                                    (interfaceType, o) => interfaceType == (Type)o, typeof(IProfile)
                                ).Length != 1
                            )
                                continue;

                            var ctor = type.GetConstructor(
                                BindingFlags.Public | BindingFlags.Instance,
                                null, System.Type.EmptyTypes, null
                            );
                            var profileInstance = (IProfile)ctor.Invoke(new object[0]);

                            profiles.Add(type.Name, profileInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load profile '{0}': {1}", filename, exc);
                    }
                }
            }

            commandLineConfig = MergeConfigurations(
                commandLineConfig,
                (from fn in filenames
                 where Path.GetExtension(fn) == ".jsilconfig"
                 select LoadConfiguration(fn)).ToArray()
            );

            if (commandLineConfig.ApplyDefaults.GetValueOrDefault(true)) {
                baseConfig = MergeConfigurations(
                    LoadConfiguration(Path.Combine(
                        GetJSILDirectory(),
                        "defaults.jsilconfig"
                    )),
                    baseConfig
                );
            }

            foreach (var solution in
                     (from fn in filenames where Path.GetExtension(fn) == ".sln" select fn)
                    ) {

                var solutionFullPath = Path.GetFullPath(solution);
                var solutionDir = Path.GetDirectoryName(solutionFullPath);

                if ((solutionDir == null) || (solutionFullPath == null)) {
                    Console.Error.WriteLine("// Can't process solution '{0}' - path seems malformed", solution);
                    continue;
                }

                var solutionConfigPath = Path.Combine(
                    solutionDir,
                    String.Format("{0}.jsilconfig", Path.GetFileName(solutionFullPath))
                );
                var solutionConfig = File.Exists(solutionConfigPath)
                    ? new Configuration[] { LoadConfiguration(solutionConfigPath) }
                    : new Configuration[] {  };

                var mergedSolutionConfig = MergeConfigurations(baseConfig, solutionConfig);
                var config = MergeConfigurations(mergedSolutionConfig, commandLineConfig);
                var buildStarted = DateTime.UtcNow.Ticks;

                var buildResult = SolutionBuilder.SolutionBuilder.Build(
                    solutionFullPath,
                    config.SolutionBuilder.Configuration,
                    config.SolutionBuilder.Platform,
                    config.SolutionBuilder.Target ?? "Build",
                    config.SolutionBuilder.LogVerbosity
                );

                var jss = new JavaScriptSerializer();
                jss.MaxJsonLength = (1024 * 1024) * 64;
                var buildResultJson = jss.Serialize(buildResult);
                buildResult = jss.Deserialize<SolutionBuilder.BuildResult>(buildResultJson);

                var buildEnded = DateTime.UtcNow.Ticks;

                IProfile profile = defaultProfile;

                foreach (var candidateProfile in profiles.Values) {
                    if (!candidateProfile.IsAppropriateForSolution(buildResult))
                        continue;

                    Console.Error.WriteLine("// Auto-selected the profile '{0}' for this project.", candidateProfile.GetType().Name);
                    profile = candidateProfile;
                    break;
                }

                var localVariables = config.ApplyTo(new VariableSet());
                localVariables["SolutionDirectory"] = () => solutionDir;

                var processStarted = DateTime.UtcNow.Ticks;
                profile.ProcessBuildResult(
                    localVariables,
                    profile.GetConfiguration(config),
                    buildResult
                );
                var processEnded = DateTime.UtcNow.Ticks;

                {
                    var logPath = localVariables.ExpandPath(String.Format(
                        "%outputdirectory%/{0}.buildlog", Path.GetFileName(solution)
                    ), false);

                    if (!Directory.Exists(Path.GetDirectoryName(logPath)))
                        Directory.CreateDirectory(Path.GetDirectoryName(logPath));

                    using (var logWriter = new StreamWriter(logPath, false, Encoding.UTF8)) {
                        logWriter.WriteLine(
                            "Build of solution '{0}' processed {1} task(s) and produced {2} result file(s):",
                            solution, buildResult.AllItemsBuilt.Length, buildResult.OutputFiles.Length
                        );

                        foreach (var of in buildResult.OutputFiles)
                            logWriter.WriteLine(of);

                        logWriter.WriteLine("----");
                        logWriter.WriteLine("Elapsed build time: {0:0000.0} second(s).", TimeSpan.FromTicks(buildEnded - buildStarted).TotalSeconds);
                        logWriter.WriteLine("Selected profile '{0}' to process results of this build.", profile.GetType().Name);
                        logWriter.WriteLine("Elapsed processing time: {0:0000.0} second(s).", TimeSpan.FromTicks(processEnded - processStarted).TotalSeconds);
                    }
                }

                var outputFiles = buildResult.OutputFiles.Concat(
                    (from eo in config.SolutionBuilder.ExtraOutputs
                     let expanded = localVariables.ExpandPath(eo, true)
                     select expanded)
                ).ToArray();

                if (outputFiles.Length > 0) {
                    buildGroups.Add(new BuildGroup {
                        BaseConfiguration = mergedSolutionConfig,
                        BaseVariables = localVariables,
                        FilesToBuild = outputFiles,
                        Profile = profile,
                    });
                }
            }

            var assemblyNames = (from fn in filenames
                                 where Path.GetExtension(fn).Contains(",") ||
                                    Path.GetExtension(fn).Contains(" ") ||
                                    Path.GetExtension(fn).Contains("=")
                                 select fn).ToArray();

            var resolver = new Mono.Cecil.DefaultAssemblyResolver();
            var metaResolver = new CachingMetadataResolver(resolver);
            var resolverParameters = new ReaderParameters {
                AssemblyResolver = resolver,
                MetadataResolver = metaResolver,
                ReadSymbols = false,
                ReadingMode = ReadingMode.Deferred,
            };
            var resolvedAssemblyPaths = (from an in assemblyNames
                                      let asm = resolver.Resolve(an, resolverParameters)
                                      where asm != null
                                      select asm.MainModule.FullyQualifiedName).ToArray();

            var mainGroup = (from fn in filenames
                             where
                                 (new[] { ".exe", ".dll" }.Contains(Path.GetExtension(fn)))
                             select fn)
                             .Concat(resolvedAssemblyPaths)
                             .ToArray();

            if (mainGroup.Length > 0) {
                var variables = commandLineConfig.ApplyTo(new VariableSet());

                buildGroups.Add(new BuildGroup {
                    BaseConfiguration = baseConfig,
                    BaseVariables = variables,
                    FilesToBuild = mainGroup,
                    Profile = defaultProfile
                });
            }

            return commandLineConfig;
        }
コード例 #6
0
        static Configuration ParseCommandLine(
            IEnumerable <string> arguments, List <BuildGroup> buildGroups,
            Dictionary <string, IProfile> profiles, Dictionary <string, IAnalyzer> analyzers,
            AssemblyCache assemblyCache
            )
        {
            var      baseConfig         = new Configuration();
            var      commandLineConfig  = new Configuration();
            IProfile defaultProfile     = new Profiles.Default();
            var      profileAssemblies  = new List <string>();
            var      analyzerAssemblies = new List <string>();

            bool[]        autoloadProfiles  = new bool[] { true };
            bool[]        autoloadAnalyzers = new bool[] { true };
            string[]      newDefaultProfile = new string[] { null };
            List <string> filenames;

            {
                var os = new Mono.Options.OptionSet {
                    { "o=|out=",
                      "Specifies the output directory for generated javascript and manifests.",
                      (path) => commandLineConfig.OutputDirectory = Path.GetFullPath(path) },
                    { "nac|noautoconfig",
                      "Suppresses automatic loading of same-named .jsilconfig files located next to solutions and/or assemblies.",
                      (b) => commandLineConfig.AutoLoadConfigFiles = b == null },
                    { "nt|nothreads",
                      "Suppresses use of multiple threads to speed up the translation process.",
                      (b) => commandLineConfig.UseThreads = b == null },
                    { "sbc|suppressbugcheck",
                      "Suppresses JSIL bug checks that detect bugs in .NET runtimes and standard libraries.",
                      (b) => commandLineConfig.RunBugChecks = b == null },

                    "Solution Builder options",
                    { "configuration=",
                      "When building one or more solution files, specifies the build configuration to use (like 'Debug').",
                      (v) => commandLineConfig.SolutionBuilder.Configuration = v },
                    { "platform=",
                      "When building one or more solution files, specifies the build platform to use (like 'x86').",
                      (v) => commandLineConfig.SolutionBuilder.Platform = v },
                    { "target=",
                      "When building one or more solution files, specifies the build target to use (like 'Build'). The default is 'Build'.",
                      (v) => commandLineConfig.SolutionBuilder.Target = v },
                    { "logVerbosity=",
                      "When building one or more solution files, specifies the level of log verbosity. Valid options are 'Quiet', 'Minimal', 'Normal', 'Detailed', and 'Diagnostic'.",
                      (v) => commandLineConfig.SolutionBuilder.LogVerbosity = v },

                    "Assembly options",
                    { "p=|proxy=",
                      "Loads a type proxy assembly to provide type information for the translator.",
                      (name) => commandLineConfig.Assemblies.Proxies.Add(Path.GetFullPath(name)) },
                    { "i=|ignore=",
                      "Specifies a regular expression pattern for assembly names that should be ignored during the translation process.",
                      (regex) => commandLineConfig.Assemblies.Ignored.Add(regex) },
                    { "s=|stub=",
                      "Specifies a regular expression pattern for assembly names that should be stubbed during the translation process. " +
                      "Stubbing forces all methods to be externals.",
                      (regex) => commandLineConfig.Assemblies.Stubbed.Add(regex) },
                    { "nd|nodeps",
                      "Suppresses the automatic loading and translation of assembly dependencies.",
                      (b) => commandLineConfig.IncludeDependencies = b == null },
                    { "nodefaults",
                      "Suppresses the default list of stubbed assemblies.",
                      (b) => commandLineConfig.ApplyDefaults = b == null },
                    { "nolocal",
                      "Disables using local proxy types from translated assemblies.",
                      (b) => commandLineConfig.UseLocalProxies = b == null },
                    { "fv=|frameworkVersion=",
                      "Specifies the version of the .NET framework proxies to use. " +
                      "This ensures that correct type information is provided (as different versions of the framework use different standard libraries). " +
                      "The only accepted value is currently '4.0'. Default: '4.0'",
                      (fv) => commandLineConfig.FrameworkVersion = double.Parse(fv) },

                    "Profile options",
                    { "nap|noautoloadprofiles",
                      "Disables automatic loading of profile assemblies from the compiler directory.",
                      (b) => autoloadProfiles[0] = (b == null) },
                    { "pa=|profileAssembly=",
                      "Loads one or more project profiles from the specified profile assembly. Note that this does not force the profiles to be used.",
                      profileAssemblies.Add },
                    { "dp=|defaultProfile=",
                      "Overrides the default profile to use for projects by specifying the name of the new default profile.",
                      (profileName) => newDefaultProfile[0] = profileName },

                    "CodeGenerator options",
                    { "os",
                      "Suppresses struct copy elimination.",
                      (b) => commandLineConfig.CodeGenerator.EliminateStructCopies = b == null },
                    { "ot",
                      "Suppresses temporary local variable elimination.",
                      (b) => commandLineConfig.CodeGenerator.EliminateTemporaries = b == null },
                    { "oo",
                      "Suppresses simplification of operator expressions and special method calls.",
                      (b) => commandLineConfig.CodeGenerator.SimplifyOperators = b == null },
                    { "ol",
                      "Suppresses simplification of loop blocks.",
                      (b) => commandLineConfig.CodeGenerator.SimplifyLoops = b == null },
                };

                filenames = os.Parse(arguments);

                if (filenames.Count == 0)
                {
                    var asmName = Assembly.GetExecutingAssembly().GetName();
                    Console.WriteLine("==== JSILc v{0}.{1}.{2} ====", asmName.Version.Major, asmName.Version.Minor, asmName.Version.Revision);
                    Console.WriteLine("Specify one or more compiled assemblies (dll/exe) to translate them. Symbols will be loaded if they exist in the same directory.");
                    Console.WriteLine("You can also specify Visual Studio solution files (sln) to build them and automatically translate their output(s).");
                    Console.WriteLine("Specify the path of a .jsilconfig file to load settings from it.");

                    os.WriteOptionDescriptions(Console.Out);

                    return(null);
                }
            }

            {
                if (autoloadProfiles[0])
                {
                    profileAssemblies.AddRange(Directory.GetFiles(
                                                   GetJSILDirectory(),
                                                   "JSIL.Profiles.*.dll"
                                                   ));
                }

                if (autoloadAnalyzers[0])
                {
                    analyzerAssemblies.AddRange(Directory.GetFiles(
                                                    GetJSILDirectory(),
                                                    "JSIL.Analysis.*.dll"
                                                    ));
                }

                foreach (var filename in profileAssemblies)
                {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        IProfile profileInstance = CreateExtensionInstance <IProfile>(fullPath);
                        if (profileInstance != null)
                        {
                            profiles.Add(profileInstance.GetType().Name, profileInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load profile '{0}': {1}", filename, exc);
                    }
                }

                foreach (var filename in analyzerAssemblies)
                {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        IAnalyzer analyzerInstance = CreateExtensionInstance <IAnalyzer>(fullPath);
                        if (analyzerInstance != null)
                        {
                            analyzers.Add(analyzerInstance.GetType().Name, analyzerInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load analyzer '{0}': {1}", filename, exc);
                    }
                }
            }

            var commandLineConfigFilenames =
                (from fn in filenames
                 where Path.GetExtension(fn) == ".jsilconfig"
                 select fn).ToArray();

            // Fail early on nonexistent configuration files
            foreach (var filename in commandLineConfigFilenames)
            {
                if (!File.Exists(filename))
                {
                    throw new FileNotFoundException(filename);
                }
            }

            commandLineConfig = MergeConfigurations(
                commandLineConfig,
                (from fn in commandLineConfigFilenames
                 select LoadConfiguration(fn)).ToArray()
                );

            if (commandLineConfig.ApplyDefaults.GetValueOrDefault(true))
            {
                baseConfig = MergeConfigurations(
                    LoadConfiguration(Path.Combine(
                                          GetJSILDirectory(),
                                          "defaults.jsilconfig"
                                          )),
                    baseConfig
                    );
            }

            foreach (var solution in
                     (from fn in filenames where Path.GetExtension(fn) == ".sln" select fn)
                     )
            {
                var solutionFullPath = Path.GetFullPath(solution);
                var solutionDir      = Path.GetDirectoryName(solutionFullPath);

                if (solutionDir == null)
                {
                    Console.Error.WriteLine("// Can't process solution '{0}' - path seems malformed", solution);
                    continue;
                }

                // Fail early if a solution file is missing
                if (!File.Exists(solutionFullPath))
                {
                    throw new FileNotFoundException(solutionFullPath);
                }

                var solutionConfigPath = Path.Combine(
                    solutionDir,
                    String.Format("{0}.jsilconfig", Path.GetFileName(solutionFullPath))
                    );
                var solutionConfig = File.Exists(solutionConfigPath)
                    ? new Configuration[] { LoadConfiguration(solutionConfigPath) }
                    : new Configuration[] {  };

                var mergedSolutionConfig = MergeConfigurations(baseConfig, solutionConfig);
                var config       = MergeConfigurations(mergedSolutionConfig, commandLineConfig);
                var buildStarted = DateTime.UtcNow.Ticks;

                var buildResult = SolutionBuilder.SolutionBuilder.Build(
                    solutionFullPath,
                    config.SolutionBuilder.Configuration,
                    config.SolutionBuilder.Platform,
                    config.SolutionBuilder.Target ?? "Build",
                    config.SolutionBuilder.LogVerbosity
                    );

                var jss = new JavaScriptSerializer {
                    MaxJsonLength = (1024 * 1024) * 64
                };

                var buildResultJson = jss.Serialize(buildResult);
                buildResult = jss.Deserialize <SolutionBuilder.BuildResult>(buildResultJson);

                var buildEnded = DateTime.UtcNow.Ticks;

                IProfile profile = defaultProfile;

                foreach (var candidateProfile in profiles.Values)
                {
                    if (!candidateProfile.IsAppropriateForSolution(buildResult))
                    {
                        continue;
                    }

                    Console.Error.WriteLine("// Auto-selected the profile '{0}' for this project.", candidateProfile.GetType().Name);
                    profile = candidateProfile;
                    break;
                }

                var localVariables = config.ApplyTo(new VariableSet());
                localVariables["SolutionDirectory"] = () => solutionDir;

                // HACK to let you use assemblyname/etc when copying output files.
                var buildResultAssembly =
                    buildResult.OutputFiles.FirstOrDefault((fn) => Path.GetExtension(fn) == ".exe") ??
                    buildResult.OutputFiles.FirstOrDefault((fn) => Path.GetExtension(fn) == ".dll");

                if (buildResultAssembly != null)
                {
                    localVariables.SetAssemblyPath(buildResultAssembly);
                }

                var processStarted = DateTime.UtcNow.Ticks;
                profile.ProcessBuildResult(
                    localVariables,
                    profile.GetConfiguration(config),
                    buildResult
                    );
                var processEnded = DateTime.UtcNow.Ticks;

                {
                    var logPath = localVariables.ExpandPath(String.Format(
                                                                "%outputdirectory%/{0}.buildlog", Path.GetFileName(solution)
                                                                ), false);

                    if (!Directory.Exists(Path.GetDirectoryName(logPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(logPath));
                    }

                    using (var logWriter = new StreamWriter(logPath, false, Encoding.UTF8)) {
                        logWriter.WriteLine(
                            "Build of solution '{0}' processed {1} task(s) and produced {2} result file(s):",
                            solution, buildResult.AllItemsBuilt.Length, buildResult.OutputFiles.Length
                            );

                        foreach (var of in buildResult.OutputFiles)
                        {
                            logWriter.WriteLine(of);
                        }

                        logWriter.WriteLine("----");
                        logWriter.WriteLine("Elapsed build time: {0:0000.0} second(s).", TimeSpan.FromTicks(buildEnded - buildStarted).TotalSeconds);
                        logWriter.WriteLine("Selected profile '{0}' to process results of this build.", profile.GetType().Name);
                        logWriter.WriteLine("Elapsed processing time: {0:0000.0} second(s).", TimeSpan.FromTicks(processEnded - processStarted).TotalSeconds);
                    }
                }

                var outputFiles = buildResult.OutputFiles.Concat(
                    (from eo in config.SolutionBuilder.ExtraOutputs
                     let expanded = localVariables.ExpandPath(eo, true)
                                    select expanded)
                    ).ToArray();

                if (outputFiles.Length > 0)
                {
                    var sa = new HashSet <string>();

                    var group = new BuildGroup {
                        BaseConfiguration = mergedSolutionConfig,
                        BaseVariables     = localVariables,
                        FilesToBuild      = PurgeDuplicateFilesFromBuildGroup(outputFiles, assemblyCache, sa),
                        Profile           = profile,
                    };
                    group.SkippedAssemblies = sa.ToArray();

                    buildGroups.Add(group);
                }
            }

            var assemblyNames = (from fn in filenames
                                 where Path.GetExtension(fn).Contains(",") ||
                                 Path.GetExtension(fn).Contains(" ") ||
                                 Path.GetExtension(fn).Contains("=")
                                 select fn).ToArray();

            var resolver           = new Mono.Cecil.DefaultAssemblyResolver();
            var metaResolver       = new CachingMetadataResolver(resolver);
            var resolverParameters = new ReaderParameters {
                AssemblyResolver = resolver,
                MetadataResolver = metaResolver,
                ReadSymbols      = false,
                ReadingMode      = ReadingMode.Deferred,
            };
            var resolvedAssemblyPaths = (from an in assemblyNames
                                         let asm = resolver.Resolve(an, resolverParameters)
                                                   where asm != null
                                                   select asm.MainModule.FullyQualifiedName).ToArray();

            var mainGroup = (from fn in filenames
                             where
                             (new[] { ".exe", ".dll" }.Contains(Path.GetExtension(fn)))
                             select fn)
                            .Concat(resolvedAssemblyPaths)
                            .ToArray();

            if (mainGroup.Length > 0)
            {
                var variables = commandLineConfig.ApplyTo(new VariableSet());

                // Fail early if any assemblies are missing
                foreach (var filename in mainGroup)
                {
                    if (!File.Exists(filename))
                    {
                        throw new FileNotFoundException(filename);
                    }
                }

                buildGroups.Add(new BuildGroup {
                    BaseConfiguration = baseConfig,
                    BaseVariables     = variables,
                    FilesToBuild      = mainGroup,
                    Profile           = defaultProfile
                });
            }

            return(commandLineConfig);
        }
コード例 #7
0
		internal static Dictionary<string, AssemblyTuple> smethod_1(IEnumerable<AssemblyFileInfo> coreAssemblyFiles)
		{
			Dictionary<string, AssemblyTuple> dictionary = new Dictionary<string, AssemblyTuple>();
			DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver();
			foreach (string current in BfCache.list_0)
			{
				if (Directory.Exists(current))
				{
					defaultAssemblyResolver.AddSearchDirectory(current);
				}
			}
			foreach (AssemblyFileInfo current2 in coreAssemblyFiles)
			{
				if (current2.Name == "Search Directory")
				{
					defaultAssemblyResolver.AddSearchDirectory(current2.Path);
				}
				else
				{
					string directoryName = Path.GetDirectoryName(current2.Path);
					defaultAssemblyResolver.AddSearchDirectory(directoryName);
				}
			}
			foreach (AssemblyFileInfo current2 in coreAssemblyFiles)
			{
				if (!(current2.Name == "Search Directory"))
				{
					AssemblyDefinition assembly;
					try
					{
						assembly = AssemblyFactory.GetAssembly(current2.Path);
					}
					catch (ImageFormatException)
					{
						throw new NitriqException("NotManagedAssembly", "The assembly \"" + current2.Name + "\" is not a managed assembly");
					}
					if (!dictionary.ContainsKey(assembly.Name.FullName))
					{
						AssemblyTuple assemblyTuple = new AssemblyTuple(assembly);
						assemblyTuple.IsCoreAssembly = true;
						assemblyTuple.Directory = Path.GetDirectoryName(current2.Path);
						dictionary.Add(assembly.Name.FullName, assemblyTuple);
					}
				}
			}
			List<AssemblyTuple> list = new List<AssemblyTuple>(dictionary.Values);
			foreach (AssemblyTuple current3 in list)
			{
				foreach (ModuleDefinition moduleDefinition in current3.Assembly.Modules)
				{
					foreach (AssemblyNameReference assemblyNameReference in moduleDefinition.AssemblyReferences)
					{
						AssemblyDefinition assemblyDefinition;
						try
						{
							assemblyDefinition = defaultAssemblyResolver.Resolve(assemblyNameReference);
						}
						catch (FileNotFoundException)
						{
							throw new NitriqException("CantResolve", "Nitriq couldn't resolve the below assembly, consider adding a search directory where this assembly can be found \r\n\r\n" + assemblyNameReference.FullName);
						}
						string fullName = assemblyNameReference.FullName;
						string fullName2 = assemblyDefinition.Name.FullName;
						if (fullName2 == fullName)
						{
							if (!dictionary.ContainsKey(fullName))
							{
								dictionary.Add(fullName, new AssemblyTuple(assemblyDefinition)
								{
									Directory = "",
									IsCoreAssembly = false
								});
							}
						}
						else if (dictionary.ContainsKey(fullName) || dictionary.ContainsKey(fullName2))
						{
							if (!dictionary.ContainsKey(fullName))
							{
								dictionary.Add(fullName, dictionary[fullName2]);
							}
							if (!dictionary.ContainsKey(fullName2))
							{
								dictionary.Add(fullName2, dictionary[fullName]);
							}
						}
						else
						{
							AssemblyTuple assemblyTuple2 = new AssemblyTuple(assemblyDefinition);
							assemblyTuple2.Directory = "";
							assemblyTuple2.IsCoreAssembly = false;
							dictionary.Add(fullName, assemblyTuple2);
							dictionary.Add(fullName2, assemblyTuple2);
						}
					}
				}
			}
			return dictionary;
		}
コード例 #8
0
ファイル: Populate.cs プロジェクト: andyhebear/Continuum
        private void DoQueueReferencedAssemblies(AssemblyDefinition assembly, string path)
        {
            var resolver = new DefaultAssemblyResolver();
            resolver.AddSearchDirectory(Path.GetDirectoryName(path));

            foreach (ModuleDefinition module in assembly.Modules)
            {
                foreach (AssemblyNameReference nr in module.AssemblyReferences)
                {
                    try
                    {
                        if (!m_resolvedAssemblies.Contains(nr.FullName))
                        {
                            AssemblyDefinition ad = resolver.Resolve(nr);	// this is a little inefficient because we load the assembly twice, but the load is not the bottleneck...
                            m_resolvedAssemblies.Add(nr.FullName);

                            Log.WriteLine(TraceLevel.Verbose, "ObjectModel", "queuing referenced {0} {1} {2}", nr.Name, nr.Culture, nr.Version);
                            lock (m_lock)
                            {
            //		Console.WriteLine("adding referenced file {0} for thread {1}", image.FileInformation.FullName, Thread.CurrentThread.ManagedThreadId);
                                m_files.Add(ad.MainModule.FullyQualifiedName);	// note that we don't need to pulse because we execute within the thread
                            }
                        }
                    }
                    catch
                    {
                        Log.WriteLine(TraceLevel.Verbose, "ObjectModel", "Couldn't resolve {0}", nr.FullName);	// this is fairly common with intermediate build steps when packaging bundles
                    }
                }
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: KAW0/Alter-Native
        private void DecompileAssembly(AssemblyDefinition adef, string outputDir, string location)
        {
            Utils.WriteToConsole("Decompiling assembly: " + adef.FullName);
            //Each visitor is responsible of changing the file if necessary (from here it is ipmossible to know the file names)
            ICSharpCode.Decompiler.ITextOutput textOutput = new ICSharpCode.Decompiler.FileTextOutput(outputDir);
            FileWritterManager.WorkingPath = outputDir;
            
            ICSharpCode.ILSpy.Language lang = null;
            //CONFIGURE OUTPUT LANGUAGE
            if (Config.ToCSharp)
            {
                 lang = OutputLanguage("C#");
            }
            else
            {
                lang = OutputLanguage("CXX");
            }

            if (Config.RecursiveDependencies)
            {
                var resolver = new DefaultAssemblyResolver();
                Utils.WriteToConsole("Adding " + location + " to resolver search directories");
                resolver.AddSearchDirectory(location);
                foreach (AssemblyNameReference anref in adef.MainModule.AssemblyReferences)
                {
                    if (!Config.IgnoreReferences.Contains(anref.Name))
                    {
                        AssemblyDefinition assembly = resolver.Resolve(anref);

                        //TODO: Change directory ?
                        DecompileAssembly(assembly, outputDir, location);
                        if (assembly == null)
                        {
                            Utils.WriteToConsole("alternative: ");
                            Utils.WriteToConsole("ERROR - could not resolve assembly " + anref.FullName + " .");
                        }
                    }
                }
            }

            //DECOMPILE FIRST TIME AND FILL THE TABLES
            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                if (!tdef.Name.Contains("<"))
                {
                    lang.DecompileType(tdef, textOutput, new ICSharpCode.ILSpy.DecompilationOptions() { FullDecompilation = false });
                }
            }

            //DECOMPILE
            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                if (!tdef.Name.Contains("<"))
                {
                    lang.DecompileType(tdef, textOutput, new ICSharpCode.ILSpy.DecompilationOptions() { FullDecompilation = false });
                    Utils.WriteToConsole("Decompiled: " + tdef.FullName);
                }
            }
        }
コード例 #10
0
        public static TypeDefinition GetTypeDefinition(TypeReference typeReference)
        {
            if (typeReference == null)
                return null;

            try
            {
                var resolver = new DefaultAssemblyResolver();
                var ass = resolver.Resolve(typeReference.Scope.Name);

                var result = ass.Modules
                    .SelectMany(x => x.Types)
                    .FirstOrDefault(td => td.FullName == typeReference.FullName);
                return result;
            }
            catch (AssemblyResolutionException)
            {
                // for now ignore...
                // TODO: figure out a better way to handle non-framework assemblies...
            }

            return null;
        }
コード例 #11
0
        public sealed override String[] GetReferences(bool keepextension)
        {
            List<string> references = new List<string>();
            DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();

            Directory.SetCurrentDirectory(Path.GetDirectoryName(_mdefsource.DeclaringType.Module.Image.FileName));

            foreach (AssemblyNameReference asmref in CompileReferences)
            {
                string reference;

                if (asmref.Name == "mscorlib" || asmref.Name.StartsWith("System"))
                {
                    reference = asmref.Name + ((keepextension) ? ".dll": string.Empty);
                }
                else
                {
                    try
                    {
                        AssemblyDefinition asmdef = resolver.Resolve(asmref);
                        reference = asmdef.MainModule.Image.FileName;
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }

                if (!references.Contains(reference))
                {
                    references.Add(reference);
                }
            }

            return references.ToArray();
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: xen2/JSIL
        static void ParseCommandLine(IEnumerable <string> arguments, List <BuildGroup> buildGroups, Dictionary <string, IProfile> profiles)
        {
            var      baseConfig        = new Configuration();
            IProfile defaultProfile    = new Profiles.Default();
            var      profileAssemblies = new List <string>();

            bool[]        autoloadProfiles  = new bool[] { true };
            string[]      newDefaultProfile = new string[] { null };
            List <string> filenames;

            {
                var os = new Mono.Options.OptionSet {
                    { "o=|out=",
                      "Specifies the output directory for generated javascript and manifests. " +
                      "You can use '%configpath%' in jsilconfig files to refer to the directory containing the configuration file, and '%assemblypath%' to refer to the directory containing the assembly being translated.",
                      (path) => baseConfig.OutputDirectory = Path.GetFullPath(path) },
                    { "nac|noautoconfig",
                      "Suppresses automatic loading of same-named .jsilconfig files located next to solutions and/or assemblies.",
                      (b) => baseConfig.AutoLoadConfigFiles = b == null },
                    { "nt|nothreads",
                      "Suppresses use of multiple threads to speed up the translation process.",
                      (b) => baseConfig.UseThreads = b == null },

                    "Solution Builder options",
                    { "configuration=",
                      "When building one or more solution files, specifies the build configuration to use (like 'Debug').",
                      (v) => baseConfig.SolutionBuilder.Configuration = v },
                    { "platform=",
                      "When building one or more solution files, specifies the build platform to use (like 'x86').",
                      (v) => baseConfig.SolutionBuilder.Platform = v },
                    { "target=",
                      "When building one or more solution files, specifies the build target to use (like 'Build'). The default is 'Build'.",
                      (v) => baseConfig.SolutionBuilder.Target = v },
                    { "logVerbosity=",
                      "When building one or more solution files, specifies the level of log verbosity. Valid options are 'Quiet', 'Minimal', 'Normal', 'Detailed', and 'Diagnostic'.",
                      (v) => baseConfig.SolutionBuilder.LogVerbosity = v },

                    "Assembly options",
                    { "p=|proxy=",
                      "Loads a type proxy assembly to provide type information for the translator.",
                      (name) => baseConfig.Assemblies.Proxies.Add(Path.GetFullPath(name)) },
                    { "i=|ignore=",
                      "Specifies a regular expression pattern for assembly names that should be ignored during the translation process.",
                      (regex) => baseConfig.Assemblies.Ignored.Add(regex) },
                    { "s=|stub=",
                      "Specifies a regular expression pattern for assembly names that should be stubbed during the translation process. " +
                      "Stubbing forces all methods to be externals.",
                      (regex) => baseConfig.Assemblies.Stubbed.Add(regex) },
                    { "nd|nodeps",
                      "Suppresses the automatic loading and translation of assembly dependencies.",
                      (b) => baseConfig.IncludeDependencies = b == null },
                    { "nodefaults",
                      "Suppresses the default list of stubbed assemblies.",
                      (b) => baseConfig.ApplyDefaults = b == null },
                    { "nolocal",
                      "Disables using local proxy types from translated assemblies.",
                      (b) => baseConfig.UseLocalProxies = b == null },
                    { "fv=|frameworkVersion=",
                      "Specifies the version of the .NET framework proxies to use. " +
                      "This ensures that correct type information is provided (as 3.5 and 4.0 use different standard libraries). " +
                      "Accepted values are '3.5' and '4.0'. Default: '4.0'",
                      (fv) => baseConfig.FrameworkVersion = double.Parse(fv) },

                    "Profile options",
                    { "nap|noautoloadprofiles",
                      "Disables automatic loading of profile assemblies from the compiler directory.",
                      (b) => autoloadProfiles[0] = (b == null) },
                    { "pa=|profileAssembly=",
                      "Loads one or more project profiles from the specified profile assembly. Note that this does not force the profiles to be used.",
                      (filename) => profileAssemblies.Add(filename) },
                    { "dp=|defaultProfile=",
                      "Overrides the default profile to use for projects by specifying the name of the new default profile..",
                      (profileName) => newDefaultProfile[0] = profileName },

                    "Optimizer options",
                    { "os",
                      "Suppresses struct copy elimination.",
                      (b) => baseConfig.Optimizer.EliminateStructCopies = b == null },
                    { "ot",
                      "Suppresses temporary local variable elimination.",
                      (b) => baseConfig.Optimizer.EliminateTemporaries = b == null },
                    { "oo",
                      "Suppresses simplification of operator expressions and special method calls.",
                      (b) => baseConfig.Optimizer.SimplifyOperators = b == null },
                    { "ol",
                      "Suppresses simplification of loop blocks.",
                      (b) => baseConfig.Optimizer.SimplifyLoops = b == null },
                };

                filenames = os.Parse(arguments);

                if (filenames.Count == 0)
                {
                    var asmName = Assembly.GetExecutingAssembly().GetName();
                    Console.WriteLine("==== JSILc v{0}.{1}.{2} ====", asmName.Version.Major, asmName.Version.Minor, asmName.Version.Revision);
                    Console.WriteLine("Specify one or more compiled assemblies (dll/exe) to translate them. Symbols will be loaded if they exist in the same directory.");
                    Console.WriteLine("You can also specify Visual Studio solution files (sln) to build them and automatically translate their output(s).");
                    Console.WriteLine("Specify the path of a .jsilconfig file to load settings from it.");

                    os.WriteOptionDescriptions(Console.Out);

                    return;
                }
            }

            {
                if (autoloadProfiles[0])
                {
                    profileAssemblies.AddRange(Directory.GetFiles(".", "JSIL.Profiles.*.dll"));
                }

                foreach (var filename in profileAssemblies)
                {
                    var fullPath = Path.GetFullPath(filename);

                    try {
                        var assembly = Assembly.LoadFile(fullPath);

                        foreach (var type in assembly.GetTypes())
                        {
                            if (
                                type.FindInterfaces(
                                    (interfaceType, o) => interfaceType == (Type)o, typeof(IProfile)
                                    ).Length != 1
                                )
                            {
                                continue;
                            }

                            var ctor = type.GetConstructor(
                                BindingFlags.Public | BindingFlags.Instance,
                                null, System.Type.EmptyTypes, null
                                );
                            var profileInstance = (IProfile)ctor.Invoke(new object[0]);

                            profiles.Add(type.Name, profileInstance);
                        }
                    } catch (Exception exc) {
                        Console.Error.WriteLine("Warning: Failed to load profile '{0}': {1}", filename, exc);
                    }
                }
            }

            baseConfig = MergeConfigurations(
                baseConfig,
                (from fn in filenames
                 where Path.GetExtension(fn) == ".jsilconfig"
                 select LoadConfiguration(fn)).ToArray()
                );

            foreach (var solution in
                     (from fn in filenames where Path.GetExtension(fn) == ".sln" select fn)
                     )
            {
                var solutionConfigPath = Path.Combine(
                    Path.GetDirectoryName(solution),
                    String.Format("{0}.jsilconfig", Path.GetFileName(solution))
                    );
                var solutionConfig = File.Exists(solutionConfigPath)
                    ? new Configuration[] { LoadConfiguration(solutionConfigPath) }
                    : new Configuration[] { };

                var config      = MergeConfigurations(baseConfig, solutionConfig);
                var buildResult = SolutionBuilder.Build(
                    solution,
                    config.SolutionBuilder.Configuration,
                    config.SolutionBuilder.Platform,
                    config.SolutionBuilder.Target ?? "Build"
                    );

                IProfile profile = defaultProfile;

                foreach (var candidateProfile in profiles.Values)
                {
                    if (!candidateProfile.IsAppropriateForSolution(buildResult))
                    {
                        continue;
                    }

                    Console.Error.WriteLine("// Auto-selected the profile '{0}' for this project.", candidateProfile.GetType().Name);
                    profile = candidateProfile;
                    break;
                }

                profile.ProcessBuildResult(
                    profile.GetConfiguration(config),
                    buildResult
                    );

                if (buildResult.OutputFiles.Length > 0)
                {
                    buildGroups.Add(new BuildGroup {
                        BaseConfiguration = config,
                        FilesToBuild      = buildResult.OutputFiles,
                        Profile           = profile
                    });
                }
            }

            var assemblyNames = (from fn in filenames
                                 where Path.GetExtension(fn).Contains(",") ||
                                 Path.GetExtension(fn).Contains(" ") ||
                                 Path.GetExtension(fn).Contains("=")
                                 select fn).ToArray();

            var resolver           = new Mono.Cecil.DefaultAssemblyResolver();
            var metaResolver       = new CachingMetadataResolver(resolver);
            var resolverParameters = new ReaderParameters {
                AssemblyResolver = resolver,
                MetadataResolver = metaResolver,
                ReadSymbols      = false,
                ReadingMode      = ReadingMode.Deferred,
            };
            var resolvedAssemblyPaths = (from an in assemblyNames
                                         let asm = resolver.Resolve(an, resolverParameters)
                                                   where asm != null
                                                   select asm.MainModule.FullyQualifiedName).ToArray();

            var mainGroup = (from fn in filenames
                             where
                             (new[] { ".exe", ".dll" }.Contains(Path.GetExtension(fn)))
                             select fn)
                            .Concat(resolvedAssemblyPaths)
                            .ToArray();

            if (mainGroup.Length > 0)
            {
                buildGroups.Add(new BuildGroup {
                    BaseConfiguration = baseConfig,
                    FilesToBuild      = mainGroup,
                    Profile           = defaultProfile
                });
            }
        }