Over a million developers have joined DZone.

How To Have Visual Studio Load XSD Schemas Automatically


At work we include XSD schemas in our Framework to allow developers to configure their web.config or app.config files and get Intellisense.   This helps to make sure they don’t make mistakes when they are configuring logging or other options for the framework (the same way the .Net Framework provides Intellisense for config files).  The problem is developers had to go to the XML menu of Visual Studio and add the schema by hand each time.  In other words, kind of a pain.  If you’ve never done this before it looks something like this:

Each time Visual Studio is opened or closed the schemas that are added have to be re-added.  I wanted to find a fix, not only for me, but the developers using our Framework as well. 

My first thought was to copy our framework schemas out to c:\program files\Microsoft Visual Studio 9.0\xml\Schemas.  But while I was looking around I found a catalog.xml file within that folder.  Interesting I thought.  I opened it up and went AHA here is the answer.

The file looks like this:

<SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
<Schema href="%InstallRoot%/Common7/IDE/Policy/Schemas/TDLSchema.xsd"
<Schema href="%InstallRoot%/Common7/IDE/Policy/Schemas/Policy.xsd"
<Schema href="%InstallRoot%/xml/schemas/%LCID%/snippetformat.xsd"
<Schema href="%InstallRoot%/xml/schemas/%LCID%/vstemplate.xsd"
<Schema href="%InstallRoot%/xml/schemas/%LCID%/Microsoft.Build.xsd"
<Schema href="%InstallRoot%/xml/schemas/%LCID%/vscontent.xsd"
<Schema href="%InstallRoot%/xml/schemas/%LCID%/customUI.xsd"
targetNamespace="http://schemas.microsoft.com/office/2006/01/customui" />
<Schema href="%InstallRoot%/common7/packages/SDM/Schema/SystemDefinitionModel.xsd"
targetNamespace="http://schemas.microsoft.com/SystemDefinitionModel/2005/1" />
<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig20.xsd" condition="%TargetFrameworkVersion% = 2.0" />
<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig30.xsd" condition="%TargetFrameworkVersion% = 3.0" />
<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig30.xsd" condition="%TargetFrameworkVersion% = 3.0" />

I copied one of the Association tags which has the extension=”config” attribute in it and made my own pointing to the location of our XSD file.  Having the ability to set the minimal version is nice as well.  I restarted Visual Studio and BAM, immediate Intellisense in my config file!

If you have been looking for a way to have XSD’s provide you Intellisense for your config files automatically, there you go.  Hope it helps.



Published at DZone with permission of Keith Elder. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}