Welcome to Team System Rocks Sign in | Join | Help

Tip: Creating Code Snippets for Custom Build Tasks

As I mentioned on my other blog, I am currently working on some Team System courseware. While developing code snippets for the Team Foundation Build content, I encountered an interesting problem. Here is the original code I came up with for the code snippet:

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <
CodeSnippet Format="1.0.0"
>
    <
Header
>
      <
Title>Custom Build Code Snippet</Title
>
    </
Header
>
    <
Snippet
>
  
   <Code Language="XML"
>
     <![CDATA[
      
<UsingTask TaskName="BuildTask.CustomTask" AssemblyFile="C:\BuildTask.dll" />
        <Target Name="BeforeDropBuild">
          <BinSize SourceDir="$(SolutionRoot)" />
        </Target>
      </Project>
     ]]>
     </
Code
>
   </
Snippet
>
 </
CodeSnippet
>
</
CodeSnippets>

When I tried importing the code snippet (Tools > Code Snippet Manager > Import) and then use it within the TfsBuild file, I got the following error:

The source of the error is the dollar sign. The code snippet framework within Visual Studio 2005 recognizes dollar signs ($) as variable identifiers. My code snippet requires a dollar sign as a means of identifying a path in Team Foundation Version Control.

To alleviate the problem, I defined a variable called "dollarsign" and assigned it the value of "$". The following updated snippet code fixes the problem:

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <
CodeSnippet Format="1.0.0"
>
    <
Header
>
      <
Title>Custom Build Code Snippet</Title
>
    </
Header
>
    <
Snippet
>
      <
Declarations
>
        <
Literal
>
         <
ID>dollarsign</ID
>
         <
ToolTip>Dollar Sign</ToolTip
>
         <
Default>$</Default
>
       </
Literal
>
     </
Declarations
>
     <
Code Language="XML"
>
     <![CDATA[
      
<UsingTask TaskName="BuildTask.CustomTask" AssemblyFile="C:\BuildTask.dll" />
        <Target Name="BeforeDropBuild">
          <BinSize SourceDir="$dollarsign$(SolutionRoot)" />
        </Target>
      </Project>
     ]]>
     </
Code
>
   </
Snippet
>
 </
CodeSnippet
>
</
CodeSnippets>

Published Monday, August 14, 2006 5:18 PM by jldavid

Comments

# VSTS Links - 08/16/2006

Wednesday, August 16, 2006 12:20 PM by Team System News
Buck Hodges on TFS Extensibility documentation on MSDN and Links to MSBuild tasks to extend your build...

# Visual Studio Team System Links

Thursday, August 17, 2006 11:57 AM by while(availableTime>0) {
Well, actually this is yesterday&#180;s news, but I&#180;m posting it anyway. Mickey Gousset has published in the&amp;nbsp;Team...
Anonymous comments are disabled