How To Have Visual Studio Load XSD Schemas Automatically
Posted by Keith Elder | Posted in .Net, Visual Studio | Posted on 07-05-2009
2
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:
1: <SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
2: <Schema href="%InstallRoot%/Common7/IDE/Policy/Schemas/TDLSchema.xsd"
3: targetNamespace="http://www.microsoft.com/schema/EnterpriseTemplates/TDLSchema"/>
4: <Schema href="%InstallRoot%/Common7/IDE/Policy/Schemas/Policy.xsd"
5: targetNamespace="http://schemas.microsoft.com/VSPolicy/PDLSchema"/>
6: <Schema href="%InstallRoot%/xml/schemas/%LCID%/snippetformat.xsd"
7: targetNamespace="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"/>
8: <Schema href="%InstallRoot%/xml/schemas/%LCID%/vstemplate.xsd"
9: targetNamespace="http://schemas.microsoft.com/developer/vstemplate/2005"/>
10: <Schema href="%InstallRoot%/xml/schemas/%LCID%/Microsoft.Build.xsd"
11: targetNamespace="http://schemas.microsoft.com/developer/msbuild/2003"/>
12: <Schema href="%InstallRoot%/xml/schemas/%LCID%/vscontent.xsd"
13: targetNamespace="http://schemas.microsoft.com/developer/vscontent/2005"/>
14: <Schema href="%InstallRoot%/xml/schemas/%LCID%/customUI.xsd"
15: targetNamespace="http://schemas.microsoft.com/office/2006/01/customui" />
16: <Schema href="%InstallRoot%/common7/packages/SDM/Schema/SystemDefinitionModel.xsd"
17: targetNamespace="http://schemas.microsoft.com/SystemDefinitionModel/2005/1" />
18: <Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig20.xsd" condition="%TargetFrameworkVersion% = 2.0" />
19: <Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig30.xsd" condition="%TargetFrameworkVersion% = 3.0" />
20: <Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig30.xsd" condition="%TargetFrameworkVersion% = 3.0" />
21: </SchemaCatalog>
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.