How to generate xsd from C# class file using visual studio command prompt?
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
user3264676
Updated on June 17, 2022Comments
-
user3264676 almost 2 years
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'
-
user3264676 about 10 yearsI don't have dll file. This file is part of my project. I just copied it to this location and trying.
-
Yair Nevet about 10 yearsNo problem, you can specify the required type to be generate as XSD. See my update.
-
user3264676 about 10 yearsI didn't understand your solution. As I'm saying I don't have dll file.
-
Yair Nevet about 10 yearsSo you must have one in order to achieve what you want. Otherwise, no way to do it with
XSD.EXE
. -
Yair Nevet about 10 yearsI assume that you are working with Visual Studio, so just compile your project, take the DLL from the BIN folder and use it as I suggest in my answer.
-
user3264676 about 10 yearsTried already, not working C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin>xsd PaymentControllerGUI.dll /type:PaymentControllerGUI.SubsystemReg.cs PaymentControllerGUI is namespace and type is SubsystemReg.cs. is this correct ??
-
Yair Nevet about 10 yearsNo, don't do it like that. This is the convention:
xsd.exe YourAssembly.dll /type:YourNamespace.YourType
-
user3264676 about 10 yearswhat should I write in place of YouNamespace.YourType?
-
user3264676 about 10 yearsDude, are you doing time pass? If you dont know please dont waste time. I have already tried this. getting error. Error: Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin\PaymentControllerGUI.dll' or one of its dependencies. Th is assembly is built by a runtime newer than the currently loaded runtime and ca nnot be loaded.
-
Yair Nevet about 10 yearsYou are trying to open your dll from the VS folder!!
-
user3264676 about 10 yearsI have copied cs file and dll file to different location. then trying
-
Yair Nevet about 10 yearsYou don't need .cs files
-
user3264676 about 10 yearsI don't know how you are doing but I'm not able to generate it. :(
-
Asad Saeeduddin about 7 years@YairNevet I salute your patience.
-
Debbie A over 3 years@YairNevet, just found this years later. I'm trying to do what you're saying. Using command prompt, cd to Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\, then enter this: xsd.exe "C:\MyProjects\Dev\Source\eFI\SCC.WebAPI\bin\SCC.WebAPI.dll" /type:SCC.WebAPI.Models.transactions Getting an error the dll is not of correct type: Could not load file or assembly, An attempt was made to load a program with an incorrect format. CAN I USE MY dll for the visual studio project where my class is defined? Or do I need a separate project with just the classes? Thanks
-
Debbie A over 3 yearsOh, I just figured it out. There's a 32-bit and a 64-bit version of the xsd.exe. Had to change directory to C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\x64 and it worked!!!! My Visual Studio Project's dll is 6-bit
-
Yair Nevet over 3 years@DebbieA great, I'm glad to hear. Please upvote if it helps as you described.