Friday, June 22, 2018

Regenerating XSD Dataset After Change

I find myself constantly having to maintain projects built with XSD datasets.  The thing I always *strongly disliked* about XSD's is their tendency to be fragile.  Whenever I make a change everything breaks and I'd end up fooling around for a 1/2 day getting it to work again.

Well, I think I've finally figured out how to make changes to an XSD, then regenerate the schema correctly.  Here are the steps that are working well for me now:

Open the XSD and make whatever changes you need.  In this sample, I'm just adding a new column to a SQL Server stored procedure.  Once I've made the change in the stored procedure, it's time to synchronize the XSD.

Go to the XSD view in Visual Studio, right-click on the object you need to change and click "Configure."

Go through all the steps of configuring that item...

You will notice that there is a file called "...Designer.cs".  This is the file auto-generated by the DataSetGenerator tool (or at least it's supposed to be auto-generated).

If this file isn't being changed, you can force it to make a new one.  First, delete the Designer.cs file (Right click => Delete).

Then right-click on the .XSD file and select "Run Custom Tool".  This will regenerate the Designer.cs file and you should be off and running.

What?  You don't have a menu item that says "Run Custom Tool"?  Then you need to add it to the XSD file type.  You do that by left-clicking on the XSD file, then go to the properties.

Under custom tool, make sure it says MSDataSetGenerator.  If it doesn't, add it.

Happy coding!

No comments:

Post a Comment