Reputation: 80
A project I am working on needs a .dll which will need some changes on runtime. Right now I compile it using Visual Studio and it works fine, but now I would like to do it programmatically.
I am currently using the CSharpCodeProvider and it seems to work just fine. But when I check the file compiled by Visual Studio and the one compiled using my program using Kdiff, they have some slight differences. I'd like them to be identical.
I already made sure I use the same framework I am using with Visual Studio which is .NET 3.5 by doing this
providerOptions.Add("CompilerVersion", "v3.5");
1.Is there any other parameters I need to put in order to make sure the compilation process is the same as the one I am currently using with Visual Studio?
2.When I decompile my programmatically compiled dll with reflector, it seems like the references are somehow not included in the project. I added them to the dll by doing so. Am I doing it wrong?
using System;
using System.Drawing;
[...]
compilerParameters.ReferencedAssemblies.Add("System.dll");
compilerParameters.ReferencedAssemblies.Add("System.Drawing.dll");
ps. I know they won't be identical when I make the changes I want to make on runtime, but right now I'm only trying to get the exact same dll.
Upvotes: 2
Views: 215
Reputation: 941377
You can never get an exact binary match, obscure stuff like the assembly's MVID and the timestamp recorded in the PE32 header will always be different.
The most pragmatic way is to write a little program that uses the Process class to run ildasm.exe with the /out
option to decompile the assemblies. Now it is simple text comparison, trivial to implement with StreamReader. With the additional great advantage that you'll now will also know exactly what is different.
Upvotes: 1