Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 537
devlop Avatar asked Jan 10 '13 20:01

devlop


People also ask

Why is Visual Studio rebuilding every time?

Sometimes, Visual Studio will always rebuild projects, even though they have recently been built and there are no changes. If you build , and then run the project will build. If you haven't disabled the “projects out of date”-dialog, it will pop up and ask you to rebuild.

What is the difference between build and rebuild in Visual Studio?

Build and rebuild are two options available in Visual Studio. The main difference between build and rebuild in Visual Studio is that build helps to complete the code files which are changed while rebuild deletes all previously compiled files and compiles the solution from scratch ignoring anything done before.

What happens when we build a project in Visual Studio?

When you create a project, Visual Studio created default build configurations for the project and the solution that contains the project. These configurations define how the solutions and projects are built and deployed.

What is build solution in Visual Studio?

Build Solution - compiles code files (dll and exe) that have changed. Rebuild Solution - Deletes all compiled files and Compiles them again regardless of whether or not the code has changed.


1 Answers

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

like image 193
Syam Avatar answered Oct 19 '22 22:10

Syam