static AssemblyLoader() { var basePath = Path.GetDirectoryName(typeof(AssemblyLoader).Assembly.Location); var beforeAssemblyPath = Path.GetFullPath(basePath + @"\..\..\..\AssemblyToProcess\bin\Debug\AssemblyToProcess.dll"); #if (!DEBUG) beforeAssemblyPath = beforeAssemblyPath.Replace("Debug", "Release"); #endif var afterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.dll"); var pbdAfterAssemblyPath = beforeAssemblyPath.Replace(".dll", "2.pdb"); var pbdBeforeAssemblyPath = beforeAssemblyPath.Replace(".dll", ".pdb"); File.Copy(beforeAssemblyPath, afterAssemblyPath, true); File.Copy(pbdBeforeAssemblyPath, pbdAfterAssemblyPath, true); var weavedAssemblyPath = beforeAssemblyPath.Replace(".dll", "3.dll"); var weavedAfterAssemblyPath = beforeAssemblyPath.Replace(".dll", "3.pdb"); var assemblyResolver = new MockAssemblyResolver { Directory = Path.GetDirectoryName(beforeAssemblyPath) }; var moduleDefinition = ModuleDefinition.ReadModule(afterAssemblyPath, new ReaderParameters { ReadSymbols = true, AssemblyResolver = assemblyResolver }); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, }; weavingTask.Execute(); moduleDefinition.Write(weavedAssemblyPath); Assembly = Assembly.LoadFile(weavedAssemblyPath); }
public IntegrationTests() { _afterAssemblyPath = _beforeAssemblyPath.Replace(".dll", "2.dll"); var afterAssemblyDocumentation = Path.ChangeExtension(_afterAssemblyPath, ".xml"); File.Copy(Path.ChangeExtension(_beforeAssemblyPath, ".xml"), afterAssemblyDocumentation, true); var assemblyResolver = new MockAssemblyResolver(); using (var moduleDefinition = ModuleDefinition.ReadModule(_beforeAssemblyPath, new ReaderParameters { AssemblyResolver = assemblyResolver })) { var projectDirectoryPath = Path.GetDirectoryName(_beforeAssemblyPath); var targetName = Path.ChangeExtension(_beforeAssemblyPath, ".ExternalAnnotations.xml"); if (File.Exists(targetName)) { File.Delete(targetName); } Debug.Assert(moduleDefinition != null, "moduleDefinition != null"); Debug.Assert(projectDirectoryPath != null, "projectDirectoryPath != null"); var weavingTask = new ModuleWeaver { ModuleDefinition = moduleDefinition, ProjectDirectoryPath = projectDirectoryPath, DocumentationFilePath = afterAssemblyDocumentation }; weavingTask.Execute(); _annotations = XDocument.Load(targetName).ToString(); _documentation = XDocument.Load(afterAssemblyDocumentation).ToString(); moduleDefinition.Write(_afterAssemblyPath); } // ReSharper disable once AssignNullToNotNullAttribute _assembly = Assembly.LoadFile(_afterAssemblyPath); }