Monday, July 27, 2009

Platform Verification Task leading to slow builds on compact framework projects

I've been experiencing an extremely high build time on a windows mobile project targeted to compact framework 2.0 before finding out what was responsible of such slowness. Fortunately solving this problem is as easy as adding a line to a configuration file.

In a Windows Mobile project I'm currently working on I experienced a very slow compilation, and I've been struggling with this problem for weeks, until I found a very simple solution.

The project is an order entry application targeted for compact framework 2.0. As of now, it is a solution made up of 7 projects, 2 of which are executables and the other ones are libraries. The first thing I noticed is that slowness occurred on one project only: the data layer. I am using LLBLGen Pro, a powerful O/R mapper that simplifies data layer development taking advantage of its visual designer and code generator. The complete list of assemblies referenced by my project is shown below:

Project References

I'm not sure whether the slowness is caused by the LLBLGen Pro or either of the System.Data.* assemblies, or maybe both. I just know that the same issue happened on Windows XP, Vista 64, using either Visual Studio 2005 and 2008. I've just reinstalled Vista Ultimate on my T61p yesterday, and at the first full build it took 30 to 60 seconds, whereas it should take just a few seconds. Fortunately I already know how to solve this issue, but I hope anyone having the same issue can find the solution here.

The most important hint came after enabling diagnostic build output (Tools menu, Options, Projects and Solutions, Build and Run, MSBuild project build output verbosity option). After setting this property to Diagnostic, on next build I found the following statistics:

Task Performance Summary:
        0 ms  RemoveDuplicates                           2 calls
        0 ms  GetDeviceFrameworkPath                     1 calls
        0 ms  Message                                    5 calls
        0 ms  AssignCulture                              1 calls
        0 ms  FindAppConfigFile                          1 calls
        0 ms  AssignTargetPath                          10 calls
        0 ms  MakeDir                                    1 calls
        0 ms  ResolveNonMSBuildProjectOutput             1 calls
        0 ms  GetFrameworkPath                           1 calls
        0 ms  Delete                                     1 calls
        1 ms  CreateProperty                             1 calls
        1 ms  ConvertToAbsolutePath                      1 calls
        1 ms  ReadLinesFromFile                          1 calls
       12 ms  Copy                                       6 calls
       20 ms  FindUnderPath                              5 calls
       32 ms  Csc                                        1 calls
       47 ms  MSBuild                                    3 calls
      110 ms  ResolveAssemblyReference                   1 calls
    18382 ms  PlatformVerificationTask                   1 calls

Build succeeded.

Time Elapsed 00:00:18.64

So it looks like the build spends 18 seconds on the "Platform Verification Task". A good explanation about what this task is can be found in this blog post, along with the solution (although I came to this blog post after I found the solution elsewhere). In fact I simply need to disable the platform verification task, by editing the Microsoft.CompactFramework.common.targets file in the C:\Windows\Microsoft.NET\Framework\v3.5 folder. Once the file is opened using your favorite text editor (mine is Notepad++), locate the <target> tag having the name attribute set to PlatformVerificationTask

<Target
    Name="PlatformVerificationTask">
    <PlatformVerificationTask
        PlatformFamilyName="$(PlatformFamilyName)"
        PlatformID="$(PlatformID)"
        SourceAssembly="@(IntermediateAssembly)"
        ReferencePath="@(ReferencePath)"
        TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
        PlatformVersion="$(TargetFrameworkVersion)"/>
</Target>

then add the Condition attribute to the PlatformVerificationTask tag as follows (the added line is the no. 4):

<Target  
    Name="PlatformVerificationTask">  
    <PlatformVerificationTask  
		Condition="'$(DoPlatformVerificationTask)'=='true'" <!-- Added -->
        PlatformFamilyName="$(PlatformFamilyName)"  
        PlatformID="$(PlatformID)"  
        SourceAssembly="@(IntermediateAssembly)"  
        ReferencePath="@(ReferencePath)"  
        TreatWarningsAsErrors="$(TreatWarningsAsErrors)"  
        PlatformVersion="$(TargetFrameworkVersion)"/>  
</Target>

Last, save and restart Visual Studio. Now the PlatformVerificationTask is not reported in the build log any longer, but most important, a normal build takes less than a second and a rebuild just a couple of seconds.

Task Performance Summary:
        0 ms  CreateProperty                             1 calls
        0 ms  ResolveNonMSBuildProjectOutput             1 calls
        0 ms  AssignTargetPath                          10 calls
        0 ms  ConvertToAbsolutePath                      1 calls
        0 ms  AssignCulture                              1 calls
        0 ms  FindAppConfigFile                          1 calls
        0 ms  Message                                    5 calls
        0 ms  RemoveDuplicates                           2 calls
        0 ms  Delete                                     1 calls
        0 ms  MakeDir                                    1 calls
        1 ms  GetDeviceFrameworkPath                     1 calls
        1 ms  GetFrameworkPath                           1 calls
        3 ms  Copy                                       6 calls
        6 ms  ReadLinesFromFile                          1 calls
       11 ms  FindUnderPath                              5 calls
       33 ms  Csc                                        1 calls
       53 ms  MSBuild                                    3 calls
       75 ms  ResolveAssemblyReference                   1 calls

Build succeeded.

Time Elapsed 00:00:00.22

References

Visual Studio For Devices blog: Platform Verification Task

0 comments:

Copyright © 2013. All Rights Reserved.