Add an XML schema to Visual Studio - visual-studio

I want Intellisense support when writing App.config sections or XML configuration files for components like NHibernate, log4net, or Unity. What options do I have to get Visual Studio to find these files and load Intellisense?
(Assume we have the schema file.)

Yes it is possible to do this. You need to associate the schema with the document and the XML editor will then provide intellisense. The following links go over how to achieve this
http://msdn.microsoft.com/en-us/library/ms255811.aspx
http://msdn.microsoft.com/en-us/library/ms255815.aspx

Open your config file, under the properties window for your config file there is a section called 'Schemas', add your schema there.

Related

can you validate xsd against xml in vs 2010?

How do I validate an xml document against an xsd in Visual Studio 2010?
Thanks.
Open you XML file in VS2010; in the Properties tool window (F4) there is a Schemas property. List the XSD you want in there. Once done, the errors/warnings will show up in the Error List tool window.
There are a few things you need. First the XML Document must be associated with the Schema:
<XmlDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Code\Schema.xsd">
</XmlDocument>
Now you need to have that Schema XSD Added into your Project. Now when you open the XML Document you should get intellisence and errors / warnings shown as you would errors in your normal C#/VB/etc/ code.

Using a DLL I've created in another VS2010 project doesn't show the intellisense tooltips

I've created a DLL to a project in Visual Studio 2010.
I'm using this DLL in another project. Using the functions is completely possible - but I can't see any tooltip.
In addition - if I'm in the same project the tooltips can be seen.
I've read some issues about using the XML file with the name of the DLL in the 2nd project, but I'm afraid I don't have any XML file (as far as I see...).
I'll appreciate your help!
Lior
In the project settings of your DLL you can specify that a XML file will be created each time the assembly is build. Thi setting is located on the "Build" tab, region "Output" and is called "XML documentation file". Mark the checkbox in front and the xml file will be created.
When you use the dll in another project you have to copy the xml file along with the assembly file to have the IntelliSense information in place.

"Add Service Reference..." to xsd

I can create a service reference in Visual Studio 2010 to an xsd. That reference downloads all the linked xsd files. However, I have 2 problems I'd like to see if there are solutions:
The URL for each xsd actually ends in .gx (e.g., http://mycompany.com/Schema1.gx). When Visual Studio imports the files, it renames them to .xsd, but in the xsd:import node, it keeps the original reference name with .gx, so my reference, once it's in Visual Studio is "not found or invalid"
for some of the xsd:import statements, the path to the referred-to .gx file is in another directory (e.g., schemaLocation="subDirectory1/Schema1.gx"). However, when they're imported, all xsd files are in the same directory in Visual Studio, but again, the xsd:import node is not modified to reflect the flatter structure.
Is there a solution to import these xsds in a valid way?
It is most likely a bug - the svcutil doesn't "refactor" the schemas. If you want a tool that handles this kind of work and more like it, this XML Schema refactoring tool should help. Download, install and create a new XML Schema Refactoring file (.xsr); add a new XML Schema collection; right click on the version 1.0, select [Import Schema Files...] command and follow the prompts. It can "slurp" online schemas, including ones referenced from, or embedded into, WSDL files, etc.

Vs2010 using log4net with Intellisense

I'm using vs2010 and I need to log a multithreading application.
So I decided to use log4net, but as I'm not used to work with this, Intellisense is gonna be worth.
I download the .xsd from http://csharptest.net/downloads/schema/log4net.xsd and put this in VSFolder/Xml/Schemas.
But, how can I say to my log4net.config to use the XSD Schema?
Use the menu XML -> Schemas...
The menu is only there if you have the config file (or any other xml file) open.
Instead of putting it into a VS folder, put it somewhere inside your solution's folder tree. It doesn't even need to be included in any projects. just put it there and it works...
Or into: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas and you're sorted once and forever.

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...
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.
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".
Marc

Resources