spierepf
spierepf

Reputation: 2934

How to tell sharpdevelop to run the xsd tool to generate .cs from .xsd

I am trying to get sharpdevelop to generate a .cs file from my .xsd. I've tried adding an entry to the solution's "Pre-build event command line" but it has no effect, not even output. So I tried adding a simple

echo "Hello World!!!"

to the pre-build just to make sure it was working. That had no effect either, suggesting that pre-build events aren't being invoked.

I also tried to assign my .xsd file a "Custom Tool" in its properties. This caused a "Cannot find custom tool" error, no matter what I put in the Custom Tool property.

Upvotes: 1

Views: 1034

Answers (1)

Matt Ward
Matt Ward

Reputation: 47987

Here is how I used xsd.exe to generate a C# file using a pre-build event in SharpDevelop 4.4.

Make sure xsd.exe is on your path. If this is configured you should be able to run xsd.exe from the command line without having to specify its full path.

With your project open in SharpDevelop, from the Project menu select Project Options. Then select the Build Events tab.

In the Pre-build event command line text box add the following:

xsd $(ProjectDir)myschema.xsd /c /out:$(ProjectDir)

This assumes you have an XML schema called myschema.xsd in your project directory.

Now build the project.

Building the project will run xsd before the rest of the project is compiled and generate a C# file in the project directory. Once this file is generated you can add the C# file to your project and write code that uses the classes in this file. So you can modify the schema and a new C# file will be generated with the changes.

In order to see echo statements in a pre-build event you need to increase the MSBuild logging level. By default SharpDevelop shows minimal output from MSBuild.

To see the echo statements, from the Tools menu select Options. In the General category select Projects and Solutions. Then change the Build verbosity to Diagnostic in the drop down list. Then when you build with SharpDevelop you will see a lot of MSBuild output, but if you search for your text you will find it in the output:

Target "PreBuildEvent" in file     "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets":
  Using "Exec" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0,     Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
  Task "Exec"
    echo 'Hello world'
    'Hello world'
  Done executing task "Exec".

Upvotes: 1

Related Questions