views:

551

answers:

3

I've been upgrading our solutions from VS 2005 to VS 2008; still targeting the .net 2.0 framework. The conversion wizard is simple and I've never had a conversion failure. The only beef that I've had so far is that I can't immediately compile after the upgrade because VS has changed some of my namespaces causing naming collisions.

For example, I have a DAL project (lets call it MyNameSpace) that has a "Clients" folder with a dataset named "dsClient".

Here is what the dataset designer class looks like before conversion:

namespace MyNameSpace
{
    public partial class dsClient : global::System.Data.DataSet
    {
    }
}

During the conversion process, VS is changing my designer class and adding the folder name to the end of the namespace so now it looks like this:

namespace MyNameSpace.Clients
{
    public partial class dsClient : global::System.Data.DataSet
    {
    }
}

The problem with this is that I have another class file in that folder with the same name:

namespace MyNameSpace
{
    public class Clients
    {
    }
}

This causes a naming collision and I have to manually go fix the changes that VS made. In some cases, VS changes the namespace name to the name of the dataset rather than the name of the folder.

Is this a config thing in the conversion wizard? I'd like to have the wizard just update the project files and leave the code alone.

+2  A: 

I believe that the namespace comes from the location of the xsd file. I think all the way back to 2003 the folder you put the xsd into made it into the namespace.

In your case, if you move the xsd to the root of the DAL project, your code should be corrected. I realize this might not be ideal, but I think that's how the DataSet generator works.

The only thing that surprises me is that the namespace didn't include the "Clients" portion in your 2005 solution. It feels like it was generated in the root, but then moved to the subfolder without regenerating.

Mark A Johnson
"The only thing that surprises me is that the namespace didn't include the "Clients" portion in your 2005 solution" - Now that I think about it, in 2005 we did have to manually change the auto generated class files after adding a new dataset. Sounds like this is a "feature" of the dataset generator.
Coov
Right. Albic's answer gives you the more permanent solution, if you want the namespace to differ from the location in the project.
Mark A Johnson
+2  A: 

You can fix this by providing the namespace the code should be generated in:

Open the properties of the xsd file and put the namespace for the code next to "Custom Tool Namespace". Then click right on your xsd file and select "Run Custom Tool" and you're done.

Albic
A: 

I wasn't aware of a "Custom tool namespace" file property! Thanks, this is exactly what I was looking for! :D