In CodeDom, it is possible to add an embedded resource to your dynamically created file by using the CompilerParameters.EmbeddedResources property. In my project, I am adding some bytes of data as an embedded resource to my dynamically created file (as shown below).
Byte[] bytes = new byte[] {1,2,3,4,5};
// Write the data to disk (I would like to avoid this step!).
File.WriteAllBytes(@"C:\EmbeddedResource.exe", bytes);
CompilerParameters cp;
cp.EmbeddedResources.Add(@"C:\EmbeddedResource.exe");
Is there some way I can store the data of ‘bytes’ in memory, and add it as an embedded resource directly from memory.
Thank you for any advice,
Evan
I’m afraid you can’t. Looking into the CSharpCodeGenerator (with Telerik’s JustDecompile or Redgate’s .NET Reflector), I found the usage of the CompilerParameters class:
They use it to create a string with all command-line parameters that are passed to the C# compiler exe (http://msdn.microsoft.com/en-us/library/6ds95cz0%28v=VS.100%29.aspx). So, at the end, I guess your code is simply compiled with csc.exe.
[]’s