Visual Studio始终为App.config选择错误的xsd [英] Visual Studio always selects the wrong xsd for App.config
问题描述
首先,我有一个具有以下配置的.NET 4.0应用程序:
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>
我遇到了与该问题相同的问题::编辑器无法识别supportedRuntime元素,从而产生提示.
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.
然后我遵循答案:我在app.config编辑器中,然后转到属性"窗口.在这里,我选择了架构"条目.
I then followed the answer: I was in the app.config editor and went to the Properties window. There I selected the Schemas entry.
我删除了对DotNetConfig.xsd的选择,而是选择了DotNetConfig35.xsd,但是VS总是自动再次添加DotNetConfig.xsd.即使我将其明确设置为不使用此架构",甚至从列表中删除架构-它也会自动再次添加到列表中并选择.
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.
如何更改架构以使用DotNetConfig35.xsd而不重新添加DotNetConfig.xsd?
How can I change the schema to use the DotNetConfig35.xsd and NOT have the DotNetConfig.xsd automatically added again?
推荐答案
我将问题解释如下:文件DotNetConfig.xsd
对<startup>
元素的定义错误(或不完整).所有DotNetConfig.xsd
,DotNetConfig35.xsd
,DotNetConfig30.xsd
和DotNetConfig20.xsd
文件的第230行包含
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" />
另一方面,Microsoft将启动设置架构描述为非空元素.因此,我建议用以下几行替换DotNetConfig.xsd
和%ProgramFiles%\Microsoft Visual Studio 10.0\Xml\Schemas
目录(或64位系统上的%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas
目录)中所有DotNetConfigXX.xsd
文件中的上述行:
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>
在进行这样的修改并重新启动Visual Studio 2010之后,您将没有所描述的警告.当然,可以以更详细的方式定义所有属性或元素的架构(特别是如果我们找到<startup>
部分的更详细的文档),但是我只想描述问题的原因以及解决该问题的一种方法.
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.
通过DotNetConfig.xsd
,DotNetConfig35.xsd
和其他DotNetConfigXX.xsd
文件之间的选择,将基于同一目录中catalog.xml
文件的内容来完成,该文件的架构在此处. catalog.xml
文件的标准版本包含以下几行:
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 = ''" />
因此,所有具有.config
扩展名的文件都将被Visual Studio解释为具有上述文件之一描述的XSD架构的文件.
So all files having .config
extension will be interpreted by Visual Studio as files with the XSD schema described by one from above files.
这篇关于Visual Studio始终为App.config选择错误的xsd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!