1

In .NET Framework 4.8, i could use AssemblyBuilder to create a new Assembly based on an existing Assembly, add some further modifications (such as encryption) and save it as a new .dll with AssemblyBuilder.Save().

In .NET 6, they removed the functionality to save an Assembly to file, along with other methods i used.

As an alternative i looked into Roslyn and how to generate Assemblies. The thing is, that i don't have the source code i want to compile into a new Assembly, but only an already compiled Assembly i want to modify.

My use case would look like this:

private void Protect(FileInfo dllSourceFile, FileInfo targetFile) {
    Assembly assembly = Assembly.LoadFrom(dllSourceFile.FullName);
    CSharpCompilation compilation = CSharpCompilation.Create(assembly);
    //...modify compilation, encrypt files
    var result = compilation.Emit(targetFile.FullName);
}

Is there any functionality in Roslyn (or .Net 6) that helps me here? Even better if it directly uses AssemblyBuilder instead of Assembly.

Florian
  • 11
  • 2
  • Have you looked at Source Generators, Fody, AspectInjector and/or Mono.Cecil? Depending on your problem, you might be able to solve your problem in a much simpler way... – Aron Dec 21 '22 at 10:13

0 Answers0