Skip Navigation Links / Posts / Posts By Category

Posts for Category: MSBuild

Feed for this Category
TaskSchema - an msbuild task

Peli just published a new MSBuild task called TaskSchema on ProjectDistributor which is kinda similar to the NAnt nantschema task.  Tasks such as this are very cool because you can use them to emit the schema (*.xsd) for a group of tasks and then copy it into the Visual Studio schema folder so that you can get intellisense when writing tasks.  I often add the following nantschema task when authoring NAnt scripts to write the xsd information directly to that folder:

<nantschema
    output="C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml\nant.xsd"
    target-ns="
http://nant.sf.net/release/0.85-rc2/nant.xsd"
    failonerror="false"
    />


With Peli's task you can pass it a list of Assemblies to schematize so it's not quite like nantschema in that you don't need the task loaded into memory.  The way that you pass the assemblies is either by specifying a single assembly or creating a task item to define a fileset, like so:


Single Assembly specified within the Task
<TaskSchema
 Assemblies="PATH TO YOUR ASSEMBLY"
 OutputPath="."
 >


Task Item to define a fileset
<ItemGroup>
 <Assemblies Include="**\*.dll" />
</ItemGroup>


<TaskSchema Assemblies="@(Assemblies)" OutputPath="." />

You can grab Peli's task (including source) from here...
    http://www.projectdistributor.net/Projects/Project.aspx?projectId=138


More about Task Items

The benefits of using a task item to define a fileset is that you can define multiple files but also that task items have metadata attached to them.  For example, if I create a task item which contains some file info, I can then use batching to reference the metadata about the items:

Batching (display a list of task items)

<ItemGroup>
    <MyItem Include="foo1.txt"/>
    <MyItem Include="foo2.txt"/>
</ItemGroup>
<Target Name="Display">
    <Exec Command="echo %(MyItem.Filename)"/>
</Target>

Displays:
foo1.txt
foo2.txt

So, from a task item you can use the %(...) syntax to access the pre-defined metadata information about the items.  Here's some reference links about this subject matter:


Task Items :
http://winfx.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_build/html/d762eff4-c92a-4b5f-a944-1ca30aa22319.asp

Pre-defined metadata :
http://winfx.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_fxgenref/html/b5e791b5-c68f-4978-ad8a-9247d03bb6c0.asp

Batching :
http://winfx.msdn.microsoft.com/library/en-us/dv_build/html/31e480f8-fe4d-4633-8c54-8ec498e2306d.asp?frame=true

Explanation of the Batching Algorithm :
http://channel9.msdn.com/wiki/default.aspx/MSBuild.BatchingAlgorithm

posted on 7/26/2005 11:59:03 PM ( 1 Comments )