xsd.exe – specified path or file name too long

I’ve just ran into an annoying issue when trying to create C# classes from several XML schemas using the XML Schema Definition Tool (a.k.a xsd.exe). This small tool allows you to process more schema files the same time by specifying the following parameter:

/P[arameters]:file.xml - Read options for various operation modes from the specified .xml file. The short form is '/p:'. (source: XML Schema Definition Tool (Xsd.exe))

Here’s a small example of file.xsd telling the tool which schema files I’d like to generate the classes from:
[code:xml]<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
  <generateClasses language='CS' namespace='MyNamespace'>   
    <schema>First.xsd</schema>
    <schema>Second.xsd</schema>
    <schema>Third.xsd</schema>
  </generateClasses>
</xsd>[/code]

After executing the following command “xsd.exe /p:file.xsd /classes” will create a file called “First_Second_Third.cs” in the same directory.
So far so good. But what happens when the list above contains a lot of schema files? You will then get the following error message:

- The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

After looking through all the available parameters of the Schema Definition Tool you’ll see that there’s no option to specify the output filename. Jeez! What now?
Good news. There’s a small bug in the tool. Putting “.\” before the file name of the last schema definition will do the trick.
[code:xml]<xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
  <generateClasses language='CS' namespace='MyNamespace'>   
    <schema>First.xsd</schema>
    <schema>Second.xsd</schema> 
    <!-- more schema files here -->
    <schema>.\Third.xsd</schema>
  </generateClasses>
</xsd>[/code]

Output file name will be: Third.cs

Lovely, isn’t it?

Comments are closed

Welcome to the blog!

Sense/Net ECM is ever evolving. Community means the world to us so we want to keep you apprised on what’s happening on our side of the woods. Want to make us happy? Add a comment and tell us what you think!

Month List