visual-studio 如何在 Visual Studio 中导出和导入 XSD 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1369999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to export and import an XSD file in Visual Studio?
提问by burnt1ce
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.
如何在 Visual Studio 中导出和导入 XSD?我只是尝试将一个 xsd 文件复制并粘贴到一个新项目中,VS2008 会自动为其创建一些包装类。当我尝试向 VS 中的表添加查询时,出现连接字符串已损坏的错误。我通过将正确的连接字符串插入 app.config 稍微修复了这个问题,但我仍然收到与连接字符串相关的错误。
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 #2This 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...
更新 #2我使用的这个 XSD 文件是通过使用 VS Studio 创建的,方法是使用本教程http://www.asp.net/learn/data-access/tutorial-01-cs.aspx. 我复制了这个 XSD 文件并将其粘贴到一个新项目中,VS 会自动为其生成代码,在本例中为“类型化数据集”。在这个新项目中,当我尝试向 XSD 文件中的表添加查询时(使用我之前提到的教程),我收到一条错误消息,指出连接字符串“xxxxxxxxx”不存在(我解释一下)。此“xxxxxxxxx”连接字符串仅存在于我从中复制 XSD 文件的项目中,而不存在于新项目中。因此,这个 xsd 包含依赖于 web.config 的信息,特别是它的连接字符串。所以复制和粘贴这个 XSD 文件是行不通的。我希望有一个向导导出工具可以去除依赖信息(即:连接字符串)及其相关设置,以便我可以将其正确添加到另一个项目并将查询添加到表中而不会出错。我希望这是有道理的...
回答by Hyman D Menendez
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:
这不起作用。问题是将现有数据集添加到项目只会将其添加为 xsd,即 Visual Studio 正在考虑 xml 架构而不是数据集。即使在 VS 2015 中也是如此。为了使其工作,在添加现有的 xsd 文件后,您必须使用 gvim 或记事本编辑项目文件并添加以下行:
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
查找具有的 ItemGroup 标记
<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.
保存文件并重新加载 Visual Studio 项目。你快完成了。右键单击 xsd 文件并选择运行自定义工具。现在你可以构建了,你应该没问题。
回答by marc_s
What do you want to do with your XSD??
你想用你的 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?
默认情况下,Visual Studio 将根据您的 XSD 创建一个“类型化数据集”。您可以使用它来查询您的数据库表并在需要时更新它。那是你要的吗?
If not: what do you want to do with your XSD inside Visual Studio then??
如果不是:那么你想在 Visual Studio 中用你的 XSD 做什么?
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.
通过执行“添加现有项目”然后选择该文件,您可以轻松地将磁盘上的现有 XSD 添加到您的 Visual Studio 项目。真的没有单独的“导入/导出”功能。
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".
如果您只想将 XSD 用于文档/信息目的,请单击该文件并在其属性窗口中,将其“构建操作”设置为“无”或“嵌入式资源”。
Marc
马克


