views:

211

answers:

2

How can I use the c++ XSD Task in a c# project? I have already created the task in the csproj file like this:

  <Target Name="BeforeBuild">
    <XSD Namespace="$(RootNamespace).Xml" Language="CS" GenerateFromSchema="classes" Sources="Xml/schema.xsd" />
  </Target>

but the build output says, although intellisense offers me the XSD task while editing the project file:

Error   1   The "XSD" task was not found. Check the following: 
1.) The name of the task in the project file is the same as the name of the task class. 
2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v4.0.30128" directory. MyProject.csproj

Oh, and I am using Visual Studio 2010 RC.

*

A: 

Forget the C++ bit, it's a distraction from the msdn page title. The tool is called XML Schema Definition Tool (Xsd.exe), and its for creating schema or code.

To debug further please set your msbuild logging level to /versbosity:diagnostic and see what headers (imported MSBUILD task definitions its pulling in).

Preet Sangha
I know about the xsd.exe tool. Right now I'm using it with a Exec task to do the job. I was just wondering if I a can somehow use the specific task that is already available (and according to msdn is a wrapper around xsd.exe)....
m0sa
Thats what I said. Run the diagnostics and see what tasks are loaded and where from. Then we can see if the correct task is actually loaded by MSBUILD or if isn't.
Preet Sangha
A: 

This is because the C++ targets are not imported. Because XSD is not one of the default tasks defined by the managed build process. you need to add a UsingTask to reference it. Add this to your csproj file:

<UsingTask TaskName="XSD" AssemblyName="Microsoft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

Good Luck, Jamie

Jamie