-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeaverHelper.cs
More file actions
35 lines (28 loc) · 1.11 KB
/
Copy pathWeaverHelper.cs
File metadata and controls
35 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.IO;
using System.Reflection;
using System.Linq;
using Mono.Cecil;
public class WeaverHelper
{
public static Assembly WeaveAssembly()
{
var projectPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\AssemblyToProcess\AssemblyToProcess.csproj"));
var assemblyPath = Path.Combine(Path.GetDirectoryName(projectPath), @"bin\Debug\AssemblyToProcess.dll");
var springBinPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\Fody\bin\debug\"));
#if (!DEBUG)
assemblyPath = assemblyPath.Replace("Debug", "Release");
springBinPath = springBinPath.Replace("Debug", "Release");
#endif
var newAssembly = assemblyPath.Replace(".dll", "2.dll");
File.Copy(assemblyPath, newAssembly, true);
var moduleDefinition = ModuleDefinition.ReadModule(newAssembly);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
};
weavingTask.Execute();
moduleDefinition.Write(newAssembly);
return Assembly.LoadFile(newAssembly);
}
}