Creating MSBuild XSD schemas for your custom tasks

Update 12/10/2012 - Since the LSS website is no longer active, I've moved the download to this site.

I've just uploaded a little utility onto our website here the downloads section on this site that should help those developers that write their own MSBuild tasks.

One of the nice features that's a little hidden in Visual Studio is its ability to provide IntelliSense and auto-completion for XML files based on the schemas that they reference, as long as the reference XSDs are included in {ProgramFiles}\{MicrosoftVisualStudioFolder}\Xml\Schemas\1033. MSBuild scripts are XML, and as such it's possible to provide information about custom tasks that you've written - the only problem is that whilst writing XSD schemas isn't exactly difficult, it can be quite involved if there are a lot of tasks that you want to expose, and keeping them in sync with your code as it changes over time can be a pain.

Enter the LSS MSBuild Schema Generator, or MSBuildSchemaGen for short. This takes one or more assemblies that contain MSBuild tasks and generates the XSD and tasks reference file (i.e. the file that contains all the UsingTasks declarations) for them. If you've documented your tasks in code and compiled your DLL with XML documentation, MSBuildSchemaGen will even annotate the schema with your documentation, enabling even richer IntelliSense.

MSBuildSchemaGen can be used from a simple command line utility, or integrated into your build process with the provided MSBuild task. (yes, the XSD and tasks files are generated by MSBuildSchemagen itself!)

What's really nice about all of this is that MSBuildSchemaGen is free for you to use right now, so get it from here here and let me know how you get on.

2 Comments

  • Harald Binkle said

    Hi,
    I just started creating custom tasks and using your great tool!
    But there is one issue:
    - my enum types are not generated, their type specification is missing in the xsd file
    What do I need to do to get them generated?

    Thanks.

    Harald

  • Mike said

    Good question! It looks like I haven't got this documented anywhere yet, sorry.

    I think you just need to add an extra "enum" code document to the task property, indicating the type of the enum that the property represents.

    For example:

    /// <summary>Gets or sets the type of the thing</summary>
    /// <enum cref="T:MyProject.MyThingEnum" />
    public string Thing { get; set; }

    Note that if you are referencing an enum defined in an external assembly, you need to provide a bit more information, like this:

    <enum cref="T:Microsoft.Web.Administration.ManagedPipelineMode" assembly-name="Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    Let me know if this works out for you!

Comments have been disabled for this content.