/// <summary> /// Processes the specified assembly. /// </summary> /// <param name="assemblyPath">The assembly path.</param> /// <param name="projectPath">The project path.</param> /// <param name="solutionPath">The solution path.</param> /// <param name="configuration">The configuration.</param> /// <param name="platform">The platform.</param> /// <param name="buildID">The build identifier.</param> /// <param name="buildTime">The build time.</param> /// <param name="entryAssemblyPath">The entry assembly path.</param> /// <returns></returns> /// <exception cref="InvalidOperationException">Could not find assembly to stitch</exception> /// <exception cref="System.InvalidOperationException">Could not find assembly to stitch</exception> public bool Process(string assemblyPath, string projectPath, string solutionPath, string configuration, string platform, Guid buildID, DateTime buildTime, string entryAssemblyPath) { var globalProperties = new Dictionary <string, string> { { "Configuration", (configuration ?? "Release").Trim() }, { "Platform", (platform ?? "AnyCPU").Trim() } }; var project = new ProjectDefinition(projectPath, Path.GetDirectoryName(assemblyPath), null, CreateAssemblyResolver(), new ProjectCollection(globalProperties)); assemblyPath = assemblyPath ?? project.TargetPath; if (assemblyPath == null || !File.Exists(assemblyPath)) { throw new InvalidOperationException("Could not find assembly to stitch"); } var pdbExtension = ".pdb"; var pdbPath = ChangeExtension(assemblyPath, pdbExtension); bool success = true; var tempAssemblyPath = assemblyPath + ".2"; File.Copy(assemblyPath, tempAssemblyPath, true); try { using (var module = ModuleDefMD.Load(tempAssemblyPath)) { if (File.Exists(pdbPath)) { module.LoadPdb(File.ReadAllBytes(pdbPath)); } bool ok; try { var context = new ProjectStitcherContext { Module = module, AssemblyPath = assemblyPath, BuildTime = buildTime, BuildID = buildID, Project = project, ProjectPath = projectPath, SolutionPath = solutionPath, TaskAssemblyPath = entryAssemblyPath, Configuration = configuration, Platform = platform, }; ok = Process(context); } catch (Exception e) { Logging.WriteError("Uncaught exception: {0}", e.ToString()); ok = false; success = false; } if (ok) { if (module.IsILOnly) { var moduleWriterOptions = new ModuleWriterOptions(module); moduleWriterOptions.WritePdb = true; moduleWriterOptions.PdbFileName = pdbPath; module.Write(assemblyPath, SetWriterOptions(project, module, moduleWriterOptions)); } else { var nativeModuleWriterOptions = new NativeModuleWriterOptions(module, true); nativeModuleWriterOptions.WritePdb = true; nativeModuleWriterOptions.PdbFileName = pdbPath; module.NativeWrite(assemblyPath, SetWriterOptions(project, module, nativeModuleWriterOptions)); } } } } finally { File.Delete(tempAssemblyPath); } return(success); }
/// <summary> /// Processes the specified module. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> protected abstract bool Process(ProjectStitcherContext context);