2012-09-21 240 views
47

我正在做一些Visual Studio 2012速成版工作。我有如下添加一个app.config XML文件:配置元素未声明

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
</configuration> 

发生的警告来了,说:“‘配置’元素未声明”的第一件事情。有谁知道为什么会发生这种情况?它看起来像元素不能在解决之前被声明。

谢谢!

这是整个XML:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<appSettings> 
<add key="Version" value="779" /> 
<add key="TimeOut" value="60000" /> 
<add key="LogFileName" value="Log.txt" /> 
<!-- your Developer Id with eBay --> 
<add key="Environment.DevId" value="" /> 
<!-- your Application Id with eBay --> 
<add key="Environment.AppId" value="" /> 
<!-- your Application Certificate with eBay --> 
<add key="Environment.CertId" value="" /> 
<!-- API Server URL --> 
<!-- For production site use: https://api.ebay.com/wsapi --> 
<!-- For Sandbox use: https://api.sandbox.ebay.com/wsapi --> 
<add key="Environment.ApiServerUrl" value="https://api.sandbox.ebay.com/wsapi" /> 
<!-- EPS Server URL --> 
<!-- For production site use: https://api.ebay.com/ws/api.dll"/--> 
<add key="Environment.EpsServerUrl" value="https://api.sandbox.ebay.com/ws/api.dll" /> 
<!-- eBay Signin URL --> 
<!-- For production site use: https://signin.ebay.com/ws/eBayISAPI.dll?SignIn --> 
<!-- https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn --> 
<add key="Environment.SignInUrl" value="https://signin.sandbox.ebay.com/ws/eBayISAPI.dll?SignIn" /> 
<!-- ViewItem URL --> 
<!-- For production site use: http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;item={0} --> 
<add key="Environment.ViewItemUrl" value="http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;item={0}" /> 
<!-- token is for both API server and EPS server --> 
<add key="UserAccount.ApiToken" value="" /> 
<!-- eBay site ID --> 
<add key="UserAccount.eBayUserSiteId" value="0" /> 
<add key="logexception" value="true"/> 
<add key="logmessages" value="true"/> 
<add key="logsdkmessages" value="true"/> 
<add key="logsdk" value="true"/> 
<add key="logfile" value="Log.txt"/> 
<!-- Rule Name--> 
<add key="RuName" value=""/> 
<!-- Set this if you access eBay API server behind a proxy server--> 
<add key="Proxy.Host" value =""/> 
<add key="Proxy.Port" value =""/> 
<!-- set proxy server username/password if necessary--> 
<add key="Proxy.Username" value=""/> 
<add key="Proxy.Password" value=""/> 

+3

您可能需要查看DotNetConfig.xsd文件的外观。可以在C:\ Program Files文件(x86)\ Microsoft Visual Studio 10.0 \ Xml \ Schemas之类的某处找到。 –

+0

确切的错误是什么,这个警告是什么?请用完整的堆栈框架? –

+0

它适用于我的VS2012 Express版本。 –

回答

17

我有同样的问题。这不是一个错误,它只是一个警告;所以你的应用程序仍应该编译。我使用了以下简单的配置文件,并且仍然产生警告。

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime 
      version="v4.0"sku=".NETFramework, 
      Version=v4.5"/> 
    </startup> 
</configuration> 

这是一个在MSDN网站上提出的问题,但似乎没有得到圆满解决。见下面的链接:

http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/18a1074f-668f-4fe3-a8d9-4440db797439

20
<configuration xmlns="schema URL"> 
    <!-- configuration settings --> 
</configuration> 

做变化,比如上面&尝试

+0

警告已消失。非常感谢你。我必须将其标记为答案。 – Giuseppe

+0

它看起来像现在配置中的元素不被Visual Studio 2012 Express Edition环境读取。 – Giuseppe

+0

@sepoto:如果你删除xmlns命名空间,那么它再次发出警告 –

196

转到XML的菜单(Visual Studio的顶级菜单项目)选择模式,并找到DotNetConfig.xsd,选择使用此模式。

您的问题将解决肯定

+1

这应该是答案。看看这个答案发布的日期(8月15日),我不太确定这个答案在问题发生时是否存在(12年9月)。 (是否?) – Ian

+1

这一项对我而言并不适用。考虑一下:https://stackoverflow.com/questions/4355278/visual-studio-always-selects-the-wrong-xsd-for-app-config – Matt

+0

这个答案解决了Visual Studio 2017的问题。无论如何,了解为什么在创建.config文件时默认不使用DotNetConfig.xsd。 – Gael

6

我不得不 - >转到XML的菜单(Visual Studio的顶级菜单项目)选择模式,并选择DotNetConfig.xsd和RazorCustomSchema.xsd和EntityFrameworkConfig_6_1_0.xsd

0

Visual Studio 2013速成版缺少DotNetConfig.xsd(https://connect.microsoft.com/VisualStudio/feedback/details/817322/dotnetconfig-xsd-files-not-present-in-vs-2013-express-for-desktop)。

所以在VS 2013点快速摆脱了警告:

警告应该消失添加架构。

0

我在xaml项目中工作时只是在自动生成的xml文件中出现此警告弹出窗口。

使用Debug-> Clean Solution和Debug-> Rebuild Solution修复了它。可能想在尝试模式之前尝试一下。

1

选择使用此模式。 DotNetConfig。XSD

XLM菜单..... Visual Studio中

完美的作品。

+0

请说明您的代码如何修复错误,而不仅仅是很多代码 - https://stackoverflow.com/help/how-to-answer –