I have a C# solution with with around 60 projects, I’m doing a multithreaded build, disabling post-build event, setting different logger, so I have written a psake wrapper around MSBuild call.
On my local machine first build is around 2 minutes, then If I repeat the same call msbuild recognizes all projects are up-to-date and second build is cca 5 seconds.
This is all super cool.
The problem is when I invoke this MSBuild from my TeamCity server (using teamcity 8.1)
As everyone would expect first build was around 2 minutes. Problem is when I forced the second build (there were no changes in source control) I thought it will be 5 seconds. But it isn’t, it is 2 minutes.
All I’m doing in my TeamCity Build step is calling this psake wrapper.
I do not have any
clean all files in the checkout directory before the build enabled or what so ever. I have a simple powershell step invoking the psake step.
This is what I’ve done so far:
Went to the agent’s working directory for this configuration and checked if DLL files are still in bin/Debug directories - they were, so next build time should use them instead of rebuild.
On the agent’s working directory i have ran psake wrapper twice in a row, first build time was 2 minutes, seconds build time was 5 seconds. So my wrapper and msbuild are doing as expected on this agent.
I have enabled MSBuild’s verbosity to normal and compare logs. On manual invoke (second time) there were
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.55 times, on TeamCity’s invoke there were just 6 times, so all other 50+ projects were rebuilt - hence the longer build time.
This leads me to believe TeamCity is doing something with the source files eventho there is no changes in source control.
Since i don’t have any clue what is TeamCity doing behind the scenes, I’d like to know where msbuild detects change and decides to rebuild. I know what projects are not skipped but I do not have the reason.
I have also duplicated my build step and second time it lasted 5 seconds.
I’m guessing this is a issue related to the temporary directory. TeamCity builds an isolated sandbox for each snapshot, so it also changes the location of temp directory. These are the one of the top lines of the TC log
[13:04:24]Clearing temporary directory: D:\TeamCity\BuildAgent2\temp\buildTmp [13:04:24]Checkout directory: D:\TeamCity\BuildAgent2\work\1955cf2ba61a55d8
Problem was temporary directory indeed. Switching temp directory before msbuild and re-setting it after, solved it.