Issue with desktop build for VC projects (in Team Build)

 

Please note that desktop clean for VC projects is not happening in post beta3 bits of Team Build. The reason is that in Team Build we are not using the default location for dropping the generated binaries. We are overriding the OutputDirectory using the overrides file (vsprops). When we invoke the build target, the binaries are dropped at the location specified by the OutputDirectory attribute of vsprops file. Unfortunately when we invoke the clean targets, the vcbuild.exe is not reading/using the overrides property. We have filed the bug on VC team but they might not fix it soon. Once VCBuild team fix there code, you have to patch the following patch to Microsoft.TeamFoundation.Build.targets file to enable desktop clean. Please replace the red text with blue one in targets file. 

 

Change from 

<Target
Name="CoreClean"

          DependsOnTargets="$(CoreCleanDependsOn)"

          Condition=" '$(SkipClean)'!='true' "

<!-- Call MSBuild /t:Clean for desktop build -->

<MSBuild

          Projects="@(SolutionToBuild)"

          Condition="'$(IsDesktopBuild)'=='true'"

          Properties="Configuration=FxCopDir=$(FxCopDir);OutDir=$(OutDir)%(ConfigurationToBuild.FlavorToBuild);Platform=%(ConfigurationToBuild.PlatformToBuild);RunCodeAnalysis=$(RunCodeAnalysis);SkipInvalidConfigurations=true;"

          Targets="Clean" />

 

 

Change to

<Target

        Name="CoreClean"

        DependsOnTargets="$(CoreCleanDependsOn)"

        Condition=" '$(SkipClean)'!='true' "

    <!-- First part of VCOverride file -->

    <CreateProperty

        Value="%3C?xml version=%221.0%22?%3E%0D%0A%3CVisualStudioPropertySheet ProjectType=%22Visual C++%22 Version=%228.00%22 Name=%22Team Build Overrides%22 OutputDirectory=%22$(OutDir)%22%3E%0D%0A" >

      <Output TaskParameter="Value" PropertyName="VCOverridesString1ForClean"/>

  </CreateProperty>

    <!-- Third part of VCOverride file -->

    <CreateProperty

      Value="%3C/VisualStudioPropertySheet%3E" >

      <Output TaskParameter="Value" PropertyName="VCOverridesString3ForClean"/>

    </CreateProperty>

    <!-- RunCodeAnalysis option -->

    <CreateProperty

       Condition=" '$(RunCodeAnalysis)'=='Always' "

       Value="RunCodeAnalysis=true" >

      <Output TaskParameter="Value" PropertyName="CodeAnalysisOptionForClean" />

    </CreateProperty>

    <!-- Second part of VCOverride file when RunCodeAnalysis is always -->

    <CreateProperty

       Condition=" '$(RunCodeAnalysis)'=='Always' "

       Value="%09%3CTool Name=%22VCCLCompilerTool%22 EnablePREfast=%22true%22 /%3E%0D%0A%09%3CTool Name=%22VCFxCopTool%22 EnableFxCop=%22true%22 /%3E%0D%0A" >

      <Output TaskParameter="Value" PropertyName="VCOverridesString2ForClean"/>

    </CreateProperty>

    <CreateProperty

       Condition=" '$(RunCodeAnalysis)'=='Never' "

       Value="RunCodeAnalysis=false" >

      <Output TaskParameter="Value" PropertyName="CodeAnalysisOptionForClean" />

    </CreateProperty>

    <!-- Second part of VCOverride file when RunCodeAnalysis is never -->

    <CreateProperty

       Condition=" '$(RunCodeAnalysis)'=='Never' "

  Value="%09%3CTool Name=%22VCCLCompilerTool%22 EnablePREfast=%22false%22 /%3E%0D%0A%09%3CTool Name=%22VCFxCopTool%22 EnableFxCop=%22false%22 /%3E%0D%0A" >

      <Output TaskParameter="Value" PropertyName="VCOverridesString2ForClean"/>

    </CreateProperty>

    <!-- ReferencePath option -->

    <CreateProperty

       Condition=" '@(AdditionalReferencePath)'!='' "

       Value="$(OutDir);@(AdditionalReferencePath)" >

      <Output TaskParameter="Value" PropertyName="ReferencePath" />

    </CreateProperty>

    <CreateProperty

       Condition=" '@(AdditionalReferencePath)'=='' "

       Value="$(OutDir)" >

      <Output TaskParameter="Value" PropertyName="ReferencePath" />

    </CreateProperty>

    <!-- Generate VCOverride file for C++ projects -->

    <WriteLinesToFile

       Condition=" '$(IsDesktopBuild)'=='true' "

       File="TFSBuild.vsprops"

       Lines="$(VCOverridesString1ForClean)$(VCOverridesString2ForClean)$(AdditionalVCOverrides)$(VCOverridesString3ForClean)"

     Overwrite="true" />

     <!-- Call MSBuild /t:Clean for desktop build -->

     <MSBuild

        Condition=" '$(IsDesktopBuild)'=='true' "

        Projects="@(SolutionToBuild)"

        Properties="Configuration=%(ConfigurationToBuild.FlavorToBuild);Platform=%(ConfigurationToBuild.PlatformToBuild);SkipInvalidConfigurations=true;VCBuildOverride=$(MSBuildProjectDirectory)\TFSBuild.vsprops;FxCopDir=$(FxCopDir);OutDir=$(OutDir);ReferencePath=$(ReferencePath);TeamBuildConstants=$(TeamBuildConstants);$(CodeAnalysisOptionForClean)"

       Targets="Clean" />

...