Fork of the Cecil library: https://github.com/jbevain/cecil
When modifying an assembly, adding many embedded resources would use an equally large amount of RAM. This fork fixes that by using a temp file for the resource buffer, so disk is used instead of RAM
NOTE: This fork is not a fix for large embedded resource files, but rather many smaller embedded resource files. For the former purpose, the solution is to split it into multiple embedded resource files a reasonable size, say 16 mb per split
Beforehand, set the static property: Mono.Cecil.EmbeddedResource.EmbeddedResourceStream
as shown in this usage example
using Mono.Cecil;
using System;
using System.IO;
namespace Program
{
class Program
{
static void Main(string[] args)
{
//create and set temp file
const string tempFilePath = @"C:\temp.tmp";
var tempFile = new FileStream(
tempFilePath,
FileMode.Create,
FileAccess.ReadWrite); //readwrite required
Mono.Cecil.EmbeddedResource.EmbeddedResourceStream = tempFile;
try
{
using (tempFile)
using (var assembly = AssemblyDefinition.ReadAssembly(@"C:\assembly.exe"))
{
//(do stuff)
//write assembly
assembly.Write(@"C:\newassembly.exe");
}
}
finally
{
Mono.Cecil.EmbeddedResource.EmbeddedResourceStream = null;
File.Delete(tempFilePath);
}
}
}
}