C# 修复:全局元素“配置”已经声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11816916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fix: The Global element 'configuration' has already been declared
提问by Michel Keijzers
I used the second solution of How to resolve "Could not find schema information for the element/attribute <xxx>"?
我使用了如何解决“找不到元素/属性 <xxx> 的架构信息”的第二种解决方案 ?
I.e. created a XSD with the button to create a scheme. I changed the stylesheet in app.config to app.xsd but now I get the warning:
即用创建方案的按钮创建了一个 XSD。我将 app.config 中的样式表更改为 app.xsd 但现在我收到警告:
The Global element 'configuration' has already been declared in app.xsd
全局元素“配置”已经在 app.xsd 中声明
Even when changing the name the warning is shown. Does anybody have a solution for this?
即使更改名称也会显示警告。有人对此有解决方案吗?
采纳答案by Tommy Grovnes
I had a similar problem to the question you are referring to, I followed these instructions and everything was fine. Make sure the EnterpriseLibrary.Configuration.xsdis in %Program Files%\Microsoft Visual Studio [version] \Xml\Schemas\first of all, then do this:
我遇到了与您所指的问题类似的问题,我按照这些说明进行操作,一切都很好。首先确保EnterpriseLibrary.Configuration.xsd是在%Program Files%\Microsoft Visual Studio [version] \Xml\Schemas\,然后执行以下操作:
Enterprise Library installs a schema into Visual Studio that provides IntelliSense? for editing Enterprise Library configuration files in the Visual Studio XML editor. You must turn on the schema before you can use it.
To enable the Enterprise Library configuration schema
Open the configuration file in Visual Studio by double-clicking it in Solution Explorer.
On the XML menu, click Schemas... to open the XML Schemas dialog.
Locate the schema named EnterpriseLibrary.Configuration.xsd. This is installed automatically. However, if it is not shown in the list, click Add and navigate to the folder %Program Files%\Microsoft Visual Studio [version] \Xml\Schemas\, then select EnterpriseLibrary.Configuration.xsd and click Open.
Change the value in the Use column to Use this schema. Then click OK.
企业库将架构安装到提供 IntelliSense 的 Visual Studio 中?用于在 Visual Studio XML 编辑器中编辑企业库配置文件。您必须先打开架构,然后才能使用它。
启用企业库配置架构
通过在解决方案资源管理器中双击它,在 Visual Studio 中打开配置文件。
在 XML 菜单上,单击架构...以打开 XML 架构对话框。
找到名为 EnterpriseLibrary.Configuration.xsd 的架构。这是自动安装的。但是,如果它未显示在列表中,请单击添加并导航到文件夹 %Program Files%\Microsoft Visual Studio [version] \Xml\Schemas\,然后选择 EnterpriseLibrary.Configuration.xsd 并单击打开。
将 Use 列中的值更改为 Use this schema。然后单击确定。
Link to the article is here, hopes this helps
文章链接在这里,希望对您有所帮助
回答by Michel Keijzers
After rebooting the system the problem is solved, meaning I do not get any warnings anymore related to the scheme.
重新启动系统后,问题解决了,这意味着我不再收到与该计划相关的任何警告。
So it seems that rebooting (and possibly some implicit restore/reset removed the warning).
所以似乎重新启动(可能还有一些隐式恢复/重置删除了警告)。
回答by Bob Horn
Rebooting didn't work for me, so I'd like to share what did work.
重新启动对我不起作用,所以我想分享一下有效的方法。
First, I just upgraded to Windows 8. This problem didn't occur before then. And this issue only happened in oneof my app.config files. So I decided to compare the problematic app.config with a good one. In Visual Studio, with the app.config open, I went to Xml -> Schemas. I noticed that the good config only had three of these schemas checked. The bad one had the same three checked, plus a DotNetConfig.xsd. After I changed the Usecolumn to automatic, for DotNetConfig.xsd, the problem went away.
首先,我刚刚升级到Windows 8。此问题在此之前没有出现。而这个问题只发生在我的一个app.config 文件中。所以我决定将有问题的 app.config 与一个好的进行比较。在 Visual Studio 中,打开 app.config,我转到Xml -> Schemas. 我注意到好的配置只检查了其中的三个模式。坏的检查了相同的三个,加上一个 DotNetConfig.xsd。在我将Use列更改为自动后,对于 DotNetConfig.xsd,问题就消失了。




回答by Charles Oppermann
With the symptoms as described in the question, and using Visual Studio 2013 (Update 4), I could see in the XML Schemas[sic] dialog that both DotNetConfig.xsdand DotNetConfig40.xsdwere selected for use.
根据问题中描述的症状,并使用 Visual Studio 2013(更新 4),我可以在XML Schemas[sic] 对话框中看到DotNetConfig.xsd和DotNetConfig40.xsd都被选中使用。
I'm using a .NET Framework 4.0 project.
我正在使用 .NET Framework 4.0 项目。
The two XSD files conflict with each other, each defining the same elements, causing the warnings to be emitted.
这两个 XSD 文件相互冲突,每个文件都定义了相同的元素,从而导致发出警告。
These schema files are contained in the %programfiles(x86)%\Microsoft Visual Studio 12.0\xml\Schemas\folder.
这些架构文件包含在%programfiles(x86)%\Microsoft Visual Studio 12.0\xml\Schemas\文件夹中。
DotNetConfig.xsdis in the 1033sub-folder and appears to be the newer, more complete version.
DotNetConfig.xsd位于1033子文件夹中,似乎是更新、更完整的版本。
No matter what settings I selected in XML Schemas, I could not deselect, or remove DotNetConfig40nor DotNetConfig. I tried "Remove", and changing the Use parameter from "Use this schema" to "Automatic" and then "Do not use this schema".
无论我在 XML Schemas 中选择什么设置,我都无法取消选择或删除DotNetConfig40或DotNetConfig。我尝试了“删除”,然后将“使用”参数从“使用此架构”更改为“自动”,然后将“不使用此架构”更改为“自动”。
No matter what was selected, for either file, when I would return to the dialog, both would be selected for use. I also tried the trick of moving to another row before pressing "OK" to no avail.
无论选择什么,对于任一文件,当我返回对话框时,都会选择使用这两个文件。我还尝试了在按“确定”之前移动到另一行的技巧,但无济于事。
Finally, I renamed the DotNetConfig40.xsdfile to DotNetConfig40 DO NOT USE.xsdto prevent it from being loaded. This immediately solved the problem.
最后,我将DotNetConfig40.xsd文件重命名为DotNetConfig40 DO NOT USE.xsd以防止它被加载。这立即解决了问题。
I'm not pleased with having to do that, and worry if it'll have an undesired side effect with other projects. I'll update this post with my results.
我对不得不这样做并不满意,并担心它是否会对其他项目产生不良影响。我会用我的结果更新这篇文章。
回答by Al Option
My issue was I went from .Net 4.5 to .Net 4.0. To resolve the issue I switched all the ticked schemas to automatic.
我的问题是我从 .Net 4.5 到 .Net 4.0。为了解决这个问题,我将所有勾选的模式切换为自动。
回答by Romonov
This issue got fixed once I closed the file in the editor that was causing these warnings and recompiled.
一旦我在编辑器中关闭了导致这些警告的文件并重新编译,这个问题就得到了解决。
回答by Ishmaeel
I struggled with this for a while as well. Turns out, my version of the problem originated from the hidden {PROJECTNAME}.SUOfile created by Visual Studio.
我也为此挣扎了一段时间。原来,我的问题版本源于{PROJECTNAME}.SUOVisual Studio 创建的隐藏文件。
My guess is, VS will cache the XSD schema associations in this file. The warnings popped up after I changed the target framework, and they disappeared after I deleted the SUO file and restarted VS.
我的猜测是,VS 将在此文件中缓存 XSD 架构关联。我更改目标框架后弹出警告,删除SUO文件并重新启动VS后它们消失了。
回答by Randall Price
Using Visual Studio 2015 Community Edition - generating a web.xsd in the root folder of my project and adding it to the schema list cleared all but one of the warnings,
使用 Visual Studio 2015 社区版 - 在我的项目的根文件夹中生成一个 web.xsd 并将其添加到架构列表中清除了除一个警告之外的所有警告,
The global element 'configuration' has already been declared'.
已声明全局元素“配置”。
Closing the web.config file in the text editor and rebuilding the project cleared this warning.
在文本编辑器中关闭 web.config 文件并重建项目清除了此警告。
回答by TheGeneral
For me i noticed i had a bunch of XML Schemasthat were duplicated, i just simply marked as Don't Useall the ones that weren't related to Visual Studio 2017. The problem immediately disappeared
对我来说,我注意到我有一堆XML Schemas重复的,我只是简单地标记为Don't Use所有与 Visual Studio 2017 无关的。问题立即消失了

