34

Is there a way to control the output filename from xsd.exe?

My specific issue is that if an imported xsd is referenced this is added to the filename.

xyz
  • 27,223
  • 29
  • 105
  • 125
NJE
  • 739
  • 1
  • 7
  • 14

4 Answers4

54

This link suggests another alternative ... using a path character in specifying the input schemas resets the generated file name. So if you use the following you will be able to control your output file name.

xsd.exe schema1.xsd schema2.xsd .\schema3.xsd

Will force xsd.exe to generate the schema3.cs file.

Note: It's a hack but up to now (VS 2010) it works.

AxelEckenberger
  • 16,628
  • 3
  • 48
  • 70
  • 3
    +1, Exactly what I needed! (works even when schemas specified in the parameters file) – Regent Feb 25 '11 at 12:28
  • 3
    Keep in mind, that the ".\" must be used on the last file. If needed, reorder your input file names in the command. – Marcel Mar 17 '14 at 09:12
  • 1
    Or, use xsd.exe /p:parameters.xml .\schema3.xsd for those joyful situations where you have a few hundred schema files to include – Roger Willcocks Dec 03 '15 at 08:22
14

To add to AxelEckenberger's answer there is a very slight improvement on the hack if you are doing this regularly (i.e in a batch script). Create an empty schema file with the output name that you want to use

Output.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" />

Then you don't need to rename the output

xsd.exe schema1.xsd schema2.xsd schema3.xsd .\Output.xsd

Now the output file will be named Output.cs.

satnhak
  • 9,407
  • 5
  • 63
  • 81
11

xsd.exe will automatically choose the output name of the file based on the input file name. You can only choose what directory to output it to with the /o switch.

That said, it's trivial to wrap this in a batch job, that would do what you want.

rename output.cs yourname.cs
Eoin Campbell
  • 43,500
  • 17
  • 101
  • 157
7

Update: Please see @Obalix's answer.

No. Only the output folder:

/o[ut]:directoryName

From here.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541