CompiledAssemblyFromFile.cs 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. // tests use WeaveAssembler, which uses AssemblyBuilder to Build().
  2. // afterwards ILPostProcessor weaves the build.
  3. // this works on windows, but build() does not run ILPP on mac atm.
  4. // we need to manually invoke ILPP with an assembly from file.
  5. //
  6. // this is in Weaver folder becuase CompilationPipeline can only be accessed
  7. // from assemblies with the name "Unity.*.CodeGen"
  8. using System.IO;
  9. using Unity.CompilationPipeline.Common.ILPostProcessing;
  10. namespace Mirror.Weaver
  11. {
  12. public class CompiledAssemblyFromFile : ICompiledAssembly
  13. {
  14. readonly string assemblyPath;
  15. public string Name => Path.GetFileNameWithoutExtension(assemblyPath);
  16. public string[] References { get; set; }
  17. public string[] Defines { get; set; }
  18. public InMemoryAssembly InMemoryAssembly { get; }
  19. public CompiledAssemblyFromFile(string assemblyPath)
  20. {
  21. this.assemblyPath = assemblyPath;
  22. byte[] peData = File.ReadAllBytes(assemblyPath);
  23. string pdbFileName = Path.GetFileNameWithoutExtension(assemblyPath) + ".pdb";
  24. byte[] pdbData = File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(assemblyPath), pdbFileName));
  25. InMemoryAssembly = new InMemoryAssembly(peData, pdbData);
  26. }
  27. }
  28. }