Why does the ASP.NET Compiler rebuild all binaries in every build?
Asked Answered
P

2

11

When I recompile my project (asp.net, c#) with aspnet_compiler the rebuilt binaries change (when compared to the previous build) even if no code changes have been made.

This, I understand, is due to the build generating a new Module Version ID (guid) each time it builds (to distinguish between builds), another similar question talks about this: Can i specify the module version id (MVID) when building a .net assembly?

The above linked question seems to suggest there is no way to rebuild a project and have the binaries match a previous build of the same unchanged code.. ok, fine, I understand - but why are all the binaries being rebuilt at all?

I would think, according to the documentation ( http://msdn.microsoft.com/en-us/library/ms229863(v=vs.80).aspx ), that unless -c is specified as an argument the aspnet_compiler should only rebuild those binaries that actually need to be (due to changed code). Am I misunderstanding or maybe missing something?

The aspnet_compiler arguments I'm using:

aspnet_compiler -f -u -fixednames -nologo -v / -p .\myproject\ .\mybuild\

Note that this issue occurs only with a WebSite project, not a Web Application project (they are compiled differently). Also this issue occurs even if you create a WebSite project and page with no functionality, and never open it or change it in anyway between builds.

Decompiling the binaries that are produced shows no differences. Comparing the binaries of two "identical" builds shows small differences in the same part of the binaries each time - which I believe is probably related to the random build guid. I've found no way of avoiding this change between builds.

Pelargonium answered 10/1, 2013 at 20:4 Comment(2)
I'm not familiar with aspnet_compiler specifically, and I could be completely off base here, but you may want to check the time stamps on your source files. I once had something similar to what you describe occur albeit with a different compiler. It turned out I somehow had a source file with a time stamp in the future, and so the compiler kept thinking the binary was out of date.Hesperus
Yes, time stamps should be checked to be sure that an unnoticed minor change (whitespace, comment, etc) forced recompilation. This guide was useful to me: blogs.msdn.com/b/jamesche/archive/2007/09/27/….Westerfield
D
2

Check out this excellent answer by Eric Lippert on how does the C# compiler makes multi passes to compile the source code. There can me many reasons why your build was not identical to the previous one, although the functionality is same.

  • Compilers replace special language features such as using block with with IL equivalents
  • The compilers does many optimizations on your code, each iteration may produce slightly different output.
  • Compilers have to create materialized names for anonymous method names and they are different each time you compile
  • And many more reasons you could easily figure it out using a dis-assembler

Check out these dis-assemblers and decompile your library or executable to gain better understanding.
http://ilspy.net/ , http://www.telerik.com/products/decompiler.aspx

Dorison answered 26/3, 2013 at 14:57 Comment(1)
This didn't solve my issue (I'm no longer sure if it is solvable), but I did appreciate the answer none-the-less; the linked to answer by Eric Lippert is a good read.Pelargonium
D
0

I've found in many cases using the aspnet_compiler especially in situations where my projects have references to other project in the same solution results in full rebuilds that are often hard to explain. (though the few times I've investigated there were "changes" even if they don't truly effect anything such as changes to whitespace, comments, etc)

I've also had problems with a number of plugins in visual studio that have done everything from manipulate tabulation and other white space, the actual project file, etc. While these changes have no noticeable change to us humans, the compiler takes one look and goes "I see a change! REBUILD ALL THE THINGS!!!"

Not sure my answer is any help, but I would disable your plugins, run the compiler, then run the compiler again and see what happens...

Dime answered 20/2, 2013 at 4:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.