Can i specify the module version id (MVID) when building a .net assembly?

谁说我不能喝 提交于 2019-11-30 17:26:58

问题


We have some shared assemblies that get build automatically every night. When there are no changes made to the sources, i would expect the assembly binaries to be exactly the same as a previous version.

However, there seem to be minor differences between assemblies.

I have done some effort to determine the difference between two builds. I used ildasm to generate an il version, and compared the resulting text versions. The only difference (in IL) is the MVID (a random guid) in the module.

Some googling tells me that the module version id gets generated by the compiler, so it is possible to determine the build source, even when everything else is the same.

This MVID creates an artificial diff betweeen builds of the same code, and an artificial checkin of the resulting assembly.

Is it possible to supply the MVID to the C# compiler?


回答1:


The ECMA-335 standard says:

The MVID is a Guid used to distinguish between two versions of the same module

Based on this description, supplying this is an argument to C# compiler will defeat it's purpose since you can pass the same MVID for different builds so I would say No.

I think the easier way would be to build only when something changes not necessarily every night.




回答2:


I realize this is a 5 year old question, but I made a Fody addin that allows you to specify a custom MVID for an assembly (needed for my own tests)

You can get it via nuget:

Install-Package Mvid.Fody

You can then specify a custom MVID like this:

[assembly: Mvid("your-guid-string-here")]

When the assembly compiles, it will have an MVID with the Guid you specified.

More info here: https://github.com/hmemcpy/Mvid.Fody



来源:https://stackoverflow.com/questions/5598291/can-i-specify-the-module-version-id-mvid-when-building-a-net-assembly

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