Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio always selects the wrong xsd for App.config

Tags:

first of all, I have a .NET 4.0 application with this configuration:

<?xml version="1.0"?> <configuration>     <startup>         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>     </startup> </configuration> 

I had the same problem like the one in this question: app.config "Could not find schema information" after converting to Visual Studio 2010 / .Net 4.0 : The supportedRuntime element was not recognized by the editor, resulting in a hint.

I then followed the answer: I was in the app.config editor and went to the Properties window. There I selected the Schemas entry.

I removed the selection of the DotNetConfig.xsd and selected the DotNetConfig35.xsd instead, but VS always automatically adds the DotNetConfig.xsd again. Even if I set it explicitely to "do not use this schema" or even remove the schema from the list - it is automatically added to the list again and selected.

Because I now have two schemas selected that define the same elements I get a lot of warnings.

How can I change the schema to use the DotNetConfig35.xsd and NOT have the DotNetConfig.xsd automatically added again?

like image 694
Sebastian P.R. Gingter Avatar asked Dec 04 '10 19:12

Sebastian P.R. Gingter


People also ask

How connect XML to XSD?

Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.

How do I import XSD files into Visual Studio?

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.

How do I view XSD files in Visual Studio?

You can access the XML Schema Explorer from a . vb file that has a Visual Basic XML literal associated with an . xsd file. To see the schema set in the XML Schema Explorer, right-click an XML node in an XML literal or an XML namespace import and select the Show in Schema Explorer command.


2 Answers

I interpret the problem as follows: the file DotNetConfig.xsd has wrong (or not full) definition of the <startup> element. Line 230 of all DotNetConfig.xsd, DotNetConfig35.xsd, DotNetConfig30.xsd and DotNetConfig20.xsd files contains

<xs:element name="startup" vs:help="configuration/startup" /> 

On the other side Microsoft describes the startup settings schema as a non-empty element. So I suggest to replace the above line in DotNetConfig.xsd and in all DotNetConfigXX.xsd files from the %ProgramFiles%\Microsoft Visual Studio 10.0\Xml\Schemas directory (or %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas directory on 64-bit systems) with the following lines:

<xs:element name="startup" vs:help="configuration/startup">     <xs:complexType>         <xs:choice minOccurs="1" maxOccurs="1">             <xs:element name="requiredRuntime" vs:help="configuration/startup/requiredRuntime">                 <xs:complexType>                     <xs:attribute name="version" type="xs:string" use="optional" />                     <xs:attribute name="safemode" type="xs:boolean" use="optional" />                 </xs:complexType>             </xs:element>             <xs:element name="supportedRuntime" minOccurs="1" maxOccurs="unbounded" vs:help="configuration/startup/supportedRuntime">                 <xs:complexType>                     <xs:attribute name="version" type="xs:string" use="optional" />                     <xs:attribute name="sku" type="xs:string" use="optional" />                 </xs:complexType>             </xs:element>         </xs:choice>         <xs:attribute name="useLegacyV2RuntimeActivationPolicy" type="xs:boolean" use="optional" />         <!-- see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx -->     </xs:complexType> </xs:element> 

After such modification and restarting of Visual Studio 2010 you will not have the warnings which you described. Of course one can define the schema of all attributes or elements in a more detailed manner (especially if we find more detailed documentation of the <startup> section), but I want to describe the reason of the problem only and one way to fix it.

By the way the choice between DotNetConfig.xsd, DotNetConfig35.xsd and other DotNetConfigXX.xsd files will be done based on the contents of the catalog.xml file from the same directory, the schema of which is described here. The standard version of the catalog.xml file contains the following lines:

<Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig20.xsd" condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v2.')" /> <Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig30.xsd" condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v3.0')" /> <Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig35.xsd" condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v3.5')" /> <Association extension="config" schema="%InstallRoot%/xml/schemas/dotNetConfig.xsd"   condition="starts-with($TargetFrameworkMoniker, '.NETFramework,Version=v4.') or $TargetFrameworkMoniker = ''" /> 

So all files having .config extension will be interpreted by Visual Studio as files with the XSD schema described by one from above files.

like image 55
Oleg Avatar answered Sep 22 '22 06:09

Oleg


When I ran into this problem, the reason un-checking the schema didn't take turned out to be having multiple instances of Visual Studio open.

(I had VS2015 open with one project and VS2013 also open at the same time with a different project.)

Note, multiple versions of Visual Studio and switching back and forth on the same project/solution also seems to be how some issues with repeated schemas occurred in the first place.

like image 31
gremlin Avatar answered Sep 18 '22 06:09

gremlin