Visual Studio 总是为 App.config 选择错误的 xsd

发布于 2024-10-05 15:39:59 字数 825 浏览 3 评论 0原文

首先,我有一个具有此配置的 .NET 4.0 应用程序:

<?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元素由编辑器编辑,产生提示。

然后我按照答案进行操作:我在 app.config 编辑器中并转到“属性”窗口。我在那里选择了模式条目。

我删除了 DotNetConfig.xsd 的选择并选择了 DotNetConfig35.xsd,但 VS 总是自动再次添加 DotNetConfig.xsd。即使我明确地将其设置为“不使用此架构”,甚至从列表中删除该架构 - 它也会自动再次添加到列表中并被选中。

因为我现在选择了两个定义相同元素的模式,所以我收到了很多警告。

如何更改架构以使用 DotNetConfig35.xsd 并且不再次自动添加 DotNetConfig.xsd?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜未央樱花落 2024-10-12 15:39:59

我对该问题的解释如下:文件 DotNetConfig.xsd 元素定义错误(或不完整)。所有 DotNetConfig.xsdDotNetConfig35.xsdDotNetConfig30.xsdDotNetConfig20.xsd 文件的第 230 行包含

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

On另一方面,微软将启动设置架构描述为非空元素。因此,我建议替换 DotNetConfig.xsd%ProgramFiles%\Microsoft Visual Studio 10.0\Xml\Schemas 中的所有 DotNetConfigXX.xsd 文件中的上述行 目录(或 64 位系统上的 %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas 目录),其中包含以下行:

<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 后您将不会收到您所描述的警告。当然,我们可以以更详细的方式定义所有属性或元素的模式(特别是如果我们找到 部分的更详细文档),但我想描述一下原因只有问题和解决它的一种方法。

顺便说一下,DotNetConfig.xsdDotNetConfig35.xsd 和其他 DotNetConfigXX.xsd 文件之间的选择将根据 DotNetConfigXX.xsd 文件的内容来完成。同一目录中的 code>catalog.xml 文件,其架构描述为 这里catalog.xml 文件的标准版本包含以下几行:

<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 架构的文件从上面的文件。

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.

青丝拂面 2024-10-12 15:39:59

当我遇到这个问题时,未取消检查架构的原因是打开了多个 Visual Studio 实例。

(我用一个项目打开 VS2015,同时用另一个项目打开 VS2013。)

注意,多个版本的 Visual Studio 以及在同一个项目/解决方案上来回切换似乎也是重复架构的一些问题的原因首先发生的。

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.

长亭外,古道边 2024-10-12 15:39:59

这是一篇旧帖子 - 但我刚刚遇到了同样的问题。

我采用的方法与 Ken Johnsrude 上面建议的方法相同 - 创建一个新的 .xsd 文件:

http://w3stack.org/question/c-how-to-fix-error-could-not-find -通过创建架构来获取属性元素的架构信息/

  1. MSVS >打开项目app.config

  2. XML>创建架构

    这将在 %TEMP% 中创建“app.xsd”

     示例:c:\users\paulsm\AppData\Local\Temp\app.xsd
    
  3. 将 app.xsd 移至项目目录

  4. App.Config,右键单击 >属性>模式> ...
    应用程序.xsd >使用>使用此架构 = YES

This is an old post - but I just encountered the same problem.

The approach I took was the same one Ken Johnsrude suggested above - to create a new .xsd file:

http://w3stack.org/question/c-how-to-fix-error-could-not-find-schema-information-for-the-attributeelement-by-creating-schema/

  1. MSVS > Open project app.config

  2. XML > Create Schema

    This will create "app.xsd" in %TEMP%

     EXAMPLE: c:\users\paulsm\AppData\Local\Temp\app.xsd
    
  3. Move app.xsd to project directory

  4. App.Config, Right-click > Properties > Schemas > ...
    app.xsd > Use > Use this schema = YES

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文