Crunch Mode Blog - A State of Mind by Developers at D2Soft Technologies

Like us on Facebook

Tip: How to compile a dataset XSD file into class under Visual Studio 2010

Here is an issue that has kept me searching for a few hours.  I have a project under Visual Studio 2010 and I needed to add an XSD file (DataSet type).  The purpose is to get a DataSet class generated automatically from the schema.  It is then quite easy to add items to the class and save them.

When using Visual Studio 2005 in a similar way, compilation is straight forward and works like a charm.  I simply put the file in the App_Code folder and I can access it from my code.

However, for Visual Studio 2010, it doesn't work.  First, I create a XSD file (dataset.xsd) into the App_Code folder and add a DataTable via the designer tool.  If I then try to access my dataset via code (like I would usually do with prior version of VS), the compiler cannot find my class.

To fix the issue, we need to solve 2 problems:

1) In the solution explorer of Visual Studio, expend the tree under the dataset.xsd file so that you can see the files under it.  Open the properties of the file dataset.Designer.cs and change the "Build Action" from Content to Compile.

2) Open the properties of file dataset.xsd and add a namespace to the "Custom Tool Namespace" field. 

Now, after making those changes, you will be able to compile and access your dataset class.  Make sure that you add your namespace with the "using" statement in your code.


 


Post your Comment: