nuget 'packages' 元素未声明警告 [英] nuget 'packages' element is not declared warning
问题描述
不是一个炫技,但在项目中使用 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 中给出警告
this gives a warning in 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.0XmlSchemas
适合我).
- 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.0XmlSchemas
for me).
然后,编辑packages.config
文件中的
标签(添加xmlns
属性):
Then, edit <packages>
tag in packages.config
file (add xmlns
attribute):
<packages xmlns="urn:packages">
现在警告应该消失(即使 packages.config 文件在 Visual Studio 中打开).
Now the warning should disappear (even if packages.config file is open in Visual Studio).
这篇关于nuget 'packages' 元素未声明警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!