Repeatable builds from same C# source code on different machines

有些话、适合烂在心里 提交于 2019-12-10 04:22:48

问题


I am trying to produce a tool which is smart enough to programmtically examine release version binaries produced by identical C# code compiled on two seperate machinces at different times and conclude that the code was identical while being able to pick up any code changes if present in the c# code used to produce these binaries.

I have tried using a number of approaches but in order to keep this short i'll just stick to the latest attempt. I run ildasm with the /text option on the binaries and replace the GUIDs for anonymous fields etc in text, but when the binaries come from different pcs i find that the text produced by ILDASM /text option is reordered. The binaries originating from the same code but compiled by same setup on different machines also appear heavily reordered. Any suggestion how one may be able to control this reordering of IL would be much appreciated ?

Cheers

PS: Any alternative strategies of reliably accomplishing this are also most welcome.


回答1:


Waiting for Eric Lippert to wake up :) - community wiki out of @mikez 's comment:

When a principal developer (Eric Lippert) on the compiler team speaks, you should listen: http://ericlippert.com/2012/05/31/past-performance-is-no-guarantee-of-future-results/ contains detailed explanation and strong recommendation for not doing it (likely in response to this precise question):

Is compiling the same C# program twice guaranteed to produce the same binary output?

No.




回答2:


I found that a solution in accordance to what Eric Lippert's mentioned in his post what his client ended up settling for can be reached by setting the processor affinity for the compilation process to 01. After this the executables/ dlls produced are almost identical in excpetion to som mvid and guids used. Running ILDASM on these binaries with the text mode and building a simple hashing tool to strip away this random stuff provides such a solution. I am just providing this for the sake of completion and to help others who may face this problem.



来源:https://stackoverflow.com/questions/11339086/repeatable-builds-from-same-c-sharp-source-code-on-different-machines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!