Arseni Mourzenko
Arseni Mourzenko

Reputation: 52311

How do I determine that an assembly actually changed?

I have a build task which performs computationally-expensive work on a few assemblies. The work is based on the IL code, and the same code always produces the same result.

I thought that it would be a good idea to cache the results of the work, but while implementing the caching, I noticed that every time the project is compiled (for instance when I click Rebuild in Visual Studio), the produced assembly is different, even when source code remains the same.

One of the differences comes from the MVID, that is Module.ModuleVersionId. It seems that there is another change, but I couldn't identify its nature yet.¹

Given that a simple diff of the assemblies will always show that the assemblies are different, what are my other options?

Decompiling the assembly to IL and trimming the MVID seems too much work for the basic task.


¹ While WinMerge shows two differences in two completely different locations at binary level, I can only see the MVID difference when comparing the assemblies in ILSpy.

Upvotes: 1

Views: 298

Answers (1)

svick
svick

Reputation: 244767

Until recently, you couldn't, at least not easily. There were many parts of the process of compiling C# or VB.NET (I'm assuming that's what you're using) that were not deterministic.

But with Roslyn 1.2 / Visual Studio 2015 Update 2, there is a new option for deterministic output. You can select this mode by passing /deterministic to csc/vbc or by manually adding <Deterministic>true</Deterministic> to your csproj/vbproj.

Upvotes: 1

Related Questions