Project template: xml file type with XSD / schema

I am creating a VS 2013 project template and one of the file types you can add to it is an XML file for which I have an XSD, but I was unable to figure out how to tell VS that when the file is added, it assigns a schema to it ...

I have something like this. Suppose the schema is Format.XSD, I poked around the schema projectitem but couldn't find anything related.

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
  <TemplateData>
    <DefaultName>type.format.ps1xml</DefaultName>
    <Name>PowerShell Format File</Name>
    <Description>An type format definition</Description>
    <ProjectType>PowerShell</ProjectType>
    <SortOrder>10</SortOrder>
    <Icon>PowerShell.ico</Icon>

  </TemplateData>
  <TemplateContent>
    <References>

    </References>
    <ProjectItem TargetFileName="$fileinputname$.format.ps1xml" ReplaceParameters="false">format.ps1xml</ProjectItem>
  </TemplateContent>
</VSTemplate>

      

+3


source to share


1 answer


Old question, but here's a record-only answer. It might help others.

Unfortunately, the VSTemplate does not allow you to specify an XSD for your XML file.

To do the trick, you need to add files to Visual Studio Chema Cache .

The schema cache is folder: % visual-studio-directory% \ Xml \ Schemas

  • Add your XSD file.
  • Add an XML file (called a catalog file) that associates your file extension with the XSD. (The directory file name can be anything, but its extension must be .xml)

Eg.



<?xml version="1.0" encoding="utf-8"?>
<SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
  <Association extension="myextension" schema="%InstallRoot%/xml/schemas/MyXsd.xsd" />
</SchemaCatalog>

      


UPDATE:

Starting with Visual Studio 2017, you can use VSIX (Visual Studio Extensibility) to install XSD files into the Visual Studio Schema folder.

See: https://docs.microsoft.com/en-us/visualstudio/extensibility/set-install-root

+1


source







All Articles