Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export and import an XSD file in Visual Studio?

How do i export and import an XSD in visual studio? I simply tried to do a copy-and-paste an xsd file into a new project and VS2008 automatically created some wrapper classes for it. When i tried to add a query to a table in VS, I get an error that the connection strings are broken. I slightly fixed that by inserting the proper connection string to app.config but i still get errors related to the connection string.

My question is not how to fix this connection string but how do i just properly export and import connection string? is there a wizard I can use? Thanks

Update #2 This XSD file that I'm using was created by using VS studio by dragging and dropping tables using this tutorial http://www.asp.net/learn/data-access/tutorial-01-cs.aspx. I copied this XSD file and pasted it into a new project and VS automatically generated code for it, which in this case a "typed dataset". In this new project, when i tried to add a query to a table in the XSD file (using the tutorial I mentioned before), I got an error stating that the connection string 'xxxxxxxxx' does not exist (im paraphrasing). This 'xxxxxxxxx' connection string exists only in the project where i copied the XSD file from and not in the new project. Therefore, this xsd contains information dependent on the web.config, specifically it's connection strings. So coping and pasting this XSD file does not work. I was hoping there was a wizard export tool that would strip away the depending information (ie: connection string) and its associated settings so that i could properly add it to another project and add a query to a table without errors. I hope that makes sense...

like image 818
burnt1ce Avatar asked Sep 02 '09 20:09

burnt1ce


2 Answers

This does not work. The problem is that adding an existing dataset to a project only adds it as an xsd i.e. Visual Studio is thinking xml schema not dataset. This is true even in VS 2015. In order to make this work, after you add the existing xsd file you must edit the project file with gvim or notepad and add the following lines:

Add in the compile section:

<Compile Include="MyDataSet.Designer.cs">
  <AutoGen>True</AutoGen>
  <DesignTime>True</DesignTime>
  <DependentUpon>MyDataSet.xsd</DependentUpon>
</Compile>

Look for the ItemGroup tag that has

<None Include="MyDataSet.xsd"/>

Change that line to look like the following and add a couple more Done tabs just so:

<None Include="MyDataSet.xsd">
  <Generator>MSDataSetGenerator</Generator>
  <LastGenOutput>MyDataSet.Designer.cs</LastGenOutput>
  <SubType>Designer</SubType>
</None>
<None Include="MyDataSet.xss">
  <DependentUpon>MyDataSet.xsd</DependentUpon>
</None>
<None Include="MyDataSet.xsc">
  <DependentUpon>MyDataSet.xsd</DependentUpon>
</None>

Save the file and reload the Visual Studio project. You are almost done. Right click on the xsd file and select run custom tool. Now you can build and you should be ok.

like image 155
Jack D Menendez Avatar answered Oct 11 '22 22:10

Jack D Menendez


What do you want to do with your XSD??

By default, Visual Studio will created a "typed dataset" based on your XSD. You can use that to query your database table and update it if needed. Is that what you want?

If not: what do you want to do with your XSD inside Visual Studio then??

You can easily just add an existing XSD on disk to your Visual Studio project by doing a "Add Existing Item" and then picking that file. There's no separate "import / export" functionality, really.

If you only want to use your XSD for documentation / information purposes, click on the file and in its properties window, set its "Build Action" to "None" or "Embedded Resource".

Set Build Action

Marc

like image 26
marc_s Avatar answered Oct 11 '22 23:10

marc_s