nuget'packages'元素未声明为警告 [英] nuget 'packages' element is not declared warning
问题描述
不是topstopper,而是在项目中使用nuget时,它会创建具有这种形状的packages.config文件
not a showstopper but when using nuget in a project, it creates a packages.config file with this shape
<?xml version="1.0" encoding="utf-8"?>
<packages>
... your packages
</packages>
这会在VS中发出警告
The 'packages' element is not declared.
问题的根源与我猜想的xml声明有关.
The origin of the problem got something to do with the xml declaration I guess.
我还认为默认定义包不应该发出警告.
Also I think that the default definition package shouldn't throw warnings.
有人知道我应该将其更改为什么,这样我就不会收到此警告吗? (即,即使我仅在打开文件时才能看到它,在某些CA规则启用的情况下,它也始终显示为警告.)
Does anyone know what should I change it to so I don't get this warning? (ie even if I can see it only when the file is open, it also shows as a warning constantly with certain CA rules on.)
推荐答案
您始终可以为"packages.config"制作简单的xsd模式,以消除此警告.为此,请创建名为"packages.xsd"的文件:
You can always make simple xsd schema for 'packages.config' to get rid of this warning. To do this, create file named "packages.xsd":
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="urn:packages" xmlns="urn:packages">
<xs:element name="packages">
<xs:complexType>
<xs:sequence>
<xs:element name="package" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:string" use="required" />
<xs:attribute name="version" type="xs:string" use="required" />
<xs:attribute name="targetFramework" type="xs:string" use="optional" />
<xs:attribute name="allowedVersions" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
此文件的位置(两个选项)
Location of this file (two options)
- 与"packages.config"文件位于同一文件夹中,
- 如果要在多个项目中共享
packages.xsd
,请将其移动到Visual Studio Schemas文件夹(路径可能略有不同,对我来说是D:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas
).
- In the same folder as 'packages.config' file,
- If you want to share
packages.xsd
across multiple projects, move it to the Visual Studio Schemas folder (the path may slightly differ, it'sD:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas
for me).
然后,在packages.config
文件中添加<packages>
标签(添加xmlns
属性):
Then, edit <packages>
tag in packages.config
file (add xmlns
attribute):
<packages xmlns="urn:packages">
现在警告应该消失(即使在Visual Studio中打开了packages.config文件).
Now the warning should disappear (even if packages.config file is open in Visual Studio).
这篇关于nuget'packages'元素未声明为警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!