首先,我有一个具有以下配置的 .NET 4.0 应用程序:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
我遇到了与此问题相同的问题:app.config "Could not find schema information" after converting to Visual Studio 2010 / .Net 4.0 :supportedRuntime 元素未被编辑器识别,导致出现提示。
然后我按照答案:我在 app.config 编辑器中,然后转到“属性”窗口。在那里我选择了 Schemas 条目。
我删除了 DotNetConfig.xsd 的选择,而是选择了 DotNetConfig35.xsd,但 VS 总是自动再次添加 DotNetConfig.xsd。即使我将其明确设置为“不使用此架构”,甚至从列表中删除该架构 - 它也会自动再次添加到列表中并被选中。
因为我现在选择了两个定义相同元素的模式,所以我收到了很多警告。
如何更改架构以使用 DotNetConfig35.xsd 而不会再次自动添加 DotNetConfig.xsd?
最佳答案
我将问题解释如下:文件 DotNetConfig.xsd
<startup>
的定义错误(或不完整)元素。第 230 行 DotNetConfig.xsd
, DotNetConfig35.xsd
, DotNetConfig30.xsd
和 DotNetConfig20.xsd
文件包含
<xs:element name="startup" vs:help="configuration/startup" />
另一方面,微软描述了 startup settings schema作为非空元素。所以我建议在
DotNetConfig.xsd
中替换上面的行总而言之 DotNetConfigXX.xsd
来自 %ProgramFiles%\Microsoft Visual Studio 10.0\Xml\Schemas
的文件目录(或 %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Xml\Schemas
64 位系统上的目录)包含以下几行:<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>
部分的更详细文档),但我只想描述问题的原因和解决方法.顺便说一下
DotNetConfig.xsd
之间的选择, DotNetConfig35.xsd
和其他 DotNetConfigXX.xsd
文件将根据 catalog.xml
的内容完成来自同一目录的文件,其架构描述为 here .标准版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 架构的文件。
关于visual-studio-2010 - Visual Studio 总是为 App.config 选择错误的 xsd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4355278/