Visual Studio 总是为 App.config 选择错误的 xsd [英] Visual Studio always selects the wrong xsd for App.config

查看:24
本文介绍了Visual Studio 总是为 App.config 选择错误的 xsd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我有一个具有此配置的 .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>

我遇到了与此问题相同的问题:app.config "找不到架构信息";转换为 Visual Studio 2010/.Net 4.0 后:编辑器无法识别 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 编辑器中并转到了属性"窗口.在那里我选择了 Schemas 条目.

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 has wrong (or not full) of the <startup> 元素.所有 DotNetConfig.xsdDotNetConfig35.xsdDotNetConfig30.xsdDotNetConfig20.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 中的所有 DotNetConfigXX.xsd 文件中的上述行 目录(或 %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas 64 位系统上的目录),包含以下几行:

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 进行此类修改和重新启动后,您将不会收到您所描述的警告.当然可以更详细地定义所有属性或元素的模式(特别是如果我们找到 部分的更详细文档),但我想描述只有问题和一种解决方法.

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.xsdDotNetConfig35.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆