How to generate xsd from C# class file using visual studio command prompt?

user3264676 picture user3264676 · Mar 5, 2014 · Viewed 10.8k times · Source

I'm using the following command, but it's not working:

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin>xsd /c /l:cs SubsystemReg.cs

Lets say this is my Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PaymentControllerGUI
{
    public class EmptyClass
    {
    }
}

and I'm trying this.

C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin>xsd /c /l:cs EmptyClass.cs

Error:

invalid command line argument: 'SubsystemReg.cs'

Answer

Yair Nevet picture Yair Nevet · Mar 5, 2014

Using the XSD.exe, you should pass the DLL file path which your class is compiled in, instead of the CS class code file itself as you pass now.

For instance, if your class is compiled in SubsystemReg.dll, call XSD.exe like that:

XSD.exe C:\SubsystemReg.dll

Here is an example from MSDN:

The following command generates XML schemas for all types in the assembly myAssembly.dll and saves them as schema0.xsd in the current directory.

xsd myAssembly.dll  

UPDATE:

You can generate XSD from DLL for a specific type by specifying the fully-qualified path of the Type, for example:

xsd.exe YourAssembly.dll /type:YourNamespace.YourType

Per your case, just do:

xsd.exe PaymentControllerGUI.dll /type:PaymentControllerGUI.EmptyClass