tags:

views:

86

answers:

2

Hi Guys,

So I'm not from the Java world but I gather that those guys have a concept of partial recompilation whereby when a solution is re-built then only the files that have changed are recompiled.

From my point of view there are two things of interest here, firstly I wonder if this sort of thing would be possible in .NET, namely when running tests. And secondly I want to know what the mechanism to achieve this involves.

With regards to the first point, what I mean is that in a lot of .NET projects that I have seen there may be several projects all referenced by a single test assembly. This essentially means that every time I want to run a test the whole world needs recompiling. Now obviously, a better partitioning of test projects to production projects would be in order, but from my experiences this doesn't happen. What I would like to see happen is that when I need to run a test then only the code required for that test is compiled.

For the second part I really am interested in the mechanism that is used to achieve partial compilation in the Java world. Are the Java IDEs the guys that track the changes to the files and only recompile what has changed or is it something else? Actually, I have several other questions here, but they may come across rather stupid, so maybe someone could just provide me with a good reference that I can read about how this is handled in Java.

Cheers, Chris.

EDIT:

Ok I obviously didn't clarify myself here, I don't want to know how MSBuild works and I don't have a specific problem with the order in which my projects build or what is being built (Playing with project settings is not granular enough for me).

What I wanted to know is what the mechanism that allows Java projects to do partial recompilation at the file level.

From my understanding it is now clear to me that Java compiles each .java file to a .class file (in some intermediate form) then all class files are archived together as a Jar file. Additionally, most IDE support this file level compilation each time a file is saved, and some even support unit test execution on each save (big time saver IMO)

Now as far as .NET is concerned, I believe that the compiled dlls aren't partitioned at this level and instead contain ALL the IL for ALL compiled classes in the project as a single file (Let me know if this is wrong).

So the question here was what options are there for us to get something similar in the .NET world, namely for executing unit tests. The only thing that I can think of is to have VS keep track of class level dependencies and have small temporary assemblies built that hold all dependencies required to execute the test. Any other suggestions welcome.

+1  A: 

It is indeed possible. Take a look at the answers to this question that has information on configuring visual studio for conditional compilation to achieve the effect you want.

You can exclude projects from your general build through the build menu..
Build->Configuration Manager->Uncheck projects that you don't want to always build.

Also

There's some limited control over this without using Configurations if you check the option to only build startup projects and dependencies on Run.
Tools -> Options -> Projects and Solutions -> Build and Run -> Only build startup projects and dependencies on Run

Quintin Robinson
I didn't explain myself well enough. I *could* exclude dependent projects that were unnecessary to execute my test, but this would be a manual process for each test, and I would have to work out what projects would be required for the test to run. My desire would be to have the IDE figure out what files needed compiling to make my test execute and only build those, as a temporary assembly. I know that this is currently not possible in VS, but I have also (maybe incorrectly) heard, that in Java their tools support compilation of only files that have changed. I wanted more info on this.
Owen
+2  A: 

There's nothing special about msbuild, it uses standard file time stamp based checking to see if the target needs to be rebuilt. As long as none of the source code files in the project have an updated time stamp then it will skip the project.

It isn't clear from your question what you might do to mess this up. Hopefully you keep your unit test code in a separate project. You can get diagnostics to see why msbuild decides to rebuild a target. Tools + Options, Project and Solutions, Build and Run, change "MSBuild project build output verbosity" to Diagnostic.

Hans Passant
The most common reason that I've seen for Visual Studio rebuilding a project all the time is when one of your .cs files has a time stamp that's in the future. Each time you build, msbuild sees that the time stamp of the .cs file is newer than the DLL and rebuilds it.
Dean Harding