.Net Compact Framework project takes very long to build, appears to freeze

On Compact Framework project I was working on from Visual Studio 2008, targeting a Windows Mobile 6  device, I noticed that doing a build was getting slower and slower. Watching the output window, the build process would start off really quick and then seem to hang around for several minutes, sometimes making Visual Studio appear “not responding”, and after that finish off real quick.

I used Process Explorer to try to see what it was doing in that time, but did not get any wiser. I tried to learn my malware scanner to ignore the locations Visual Studio was reading from and writing to, thinking maybe it was slowing the compiler down because of troubles verifying executables targeting a non-desktop-Windows platform. But that was not it either.

Until I read a tip somewhere to increase the build output verbosity. That can be done from Tools / Options / Projects and Solutions / Build and Run:

So I set that to diagnostic, launched another build and went for a cup of coffee.

About ten minutes later I returned and found, at the end of a really big pile of text, a.o. this:

Task Performance Summary:
        0 ms  FindAppConfigFile                          1 calls
        0 ms  AssignTargetPath                          10 calls
        0 ms  Delete                                     1 calls
        0 ms  ReadLinesFromFile                          1 calls
        0 ms  CreateProperty                             1 calls
        0 ms  GetDeviceFrameworkPath                     1 calls
        0 ms  GetFrameworkPath                           1 calls
        0 ms  ResolveNonMSBuildProjectOutput             1 calls
        1 ms  AssignCulture                              1 calls
        1 ms  ConvertToAbsolutePath                      1 calls
        2 ms  RemoveDuplicates                           2 calls
        2 ms  Message                                    5 calls
        5 ms  MakeDir                                    5 calls
        6 ms  CreateVisualBasicManifestResourceName      2 calls
        8 ms  GenerateResource                           1 calls
        9 ms  ResolveAssemblyReference                   1 calls
        9 ms  Copy                                       6 calls
       16 ms  FindUnderPath                              5 calls
       21 ms  AddHighDPIResource                         1 calls
       42 ms  MSBuild                                    3 calls
      193 ms  AL                                         4 calls
      249 ms  Vbc                                        1 calls
    329655 ms  PlatformVerificationTask                   1 calls

Build succeeded.

Time Elapsed 00:05:30.33
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========

Woah! PlatformVerificationTask? What’s that thing? I don’t know what it’s doing, and why is it taking so long? Well, i now had an extra keyword to google, which lead me to this discussion and another (which unfortunately could only be accessed from google’s cache).

It turns out that, for my situation, it’s safe to turn the entire task off.

So I opened the file


and looked up the key:

<Target Name="PlatformVerificationTask">

I changed that to:

<Target Name="PlatformVerificationTask" Condition="0==1">

(Note that with UAC you need to be elevated to save to that location). The condition obviously always evaluates to false, which effectively disables the task. Close the solution, re-open and build again. Now it’s done in seconds again. Great!

If you can’t disable the task completely like I did, because it’s a build machine, because you need it for some projects and not for some other, etc., there are some suggestions in the linked thread about making the task conditional.