xml nuget 'packages' 元素未声明为警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6774578/
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
nuget 'packages' element is not declared warning
提问by roundcrisis
not a showstopper but when using nuget in a project, it creates a packages.config file with this shape
不是 showstopper 但在项目中使用 nuget 时,它会创建一个具有此形状的 packages.config 文件
<?xml version="1.0" encoding="utf-8"?>
<packages>
... your packages
</packages>
this gives a warning in VS
这在 VS 中发出警告
The 'packages' element is not declared.
The origin of the problem got something to do with the xml declaration I guess.
问题的根源与我猜的 xml 声明有关。
Also I think that the default definition package shouldn't throw warnings.
另外我认为默认定义包不应该抛出警告。
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.)
有谁知道我应该把它改成什么,这样我就不会收到这个警告?(即,即使我只有在文件打开时才能看到它,它也会在某些 CA 规则开启的情况下不断显示为警告。)
采纳答案by ?ukasz Wiatrak
You can always make simple xsd schema for 'packages.config' to get rid of this warning. To do this, create file named "packages.xsd":
您始终可以为“packages.config”创建简单的 xsd 架构以消除此警告。为此,请创建名为“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)
此文件的位置(两个选项)
- In the same folder as 'packages.config' file,
- If you want to share
packages.xsdacross 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\Schemasfor me).
- 在与“packages.config”文件相同的文件夹中,
- 如果要
packages.xsd跨多个项目共享,请将其移动到 Visual Studio Schemas 文件夹(路径可能略有不同,这是D:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas给我的)。
Then, edit <packages>tag in packages.configfile (add xmlnsattribute):
然后,<packages>在packages.config文件中编辑标签(添加xmlns属性):
<packages xmlns="urn:packages">
Now the warning should disappear (even if packages.config file is open in Visual Studio).
现在警告应该消失(即使在 Visual Studio 中打开了 packages.config 文件)。
回答by Tzvi Gregory Kaidanov
You will see it only when the file is open. When you'll close the file in Visual Studio the warnings goes away
只有在文件打开时您才会看到它。当您在 Visual Studio 中关闭文件时,警告消失
回答by Stefan Z Camilleri
Actually the correct answer to this is to just add the schema to your document, like so
实际上,对此的正确答案是将架构添加到您的文档中,就像这样
<packages xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
...and you're done :)
......你就完成了:)
If the XSD is not already cached and unavailable, you can add it as follows from the NuGet console
如果 XSD 尚未缓存且不可用,则可以从 NuGet 控制台按如下方式添加
Install-Package NuGet.Manifest.Schema -Version 2.0.0
Once this is done, as noted in a comment below, you may want to move it from your current folder to the official schema folder that is found in
完成此操作后,如下面的评论中所述,您可能希望将其从当前文件夹移动到位于
%VisualStudioPath%\Xml\Schemas
回答by Baris
None of the answers will solve your problem permanently. If you go to the path of adding XSD (From Xml menu, select "Create schema"), you will end up having problems with the package manager as it will clean up your packages.config file when you add a new package.
没有一个答案可以永久解决您的问题。如果您转到添加 XSD 的路径(从 Xml 菜单中,选择“创建架构”),您最终会遇到包管理器问题,因为它会在您添加新包时清理您的 packages.config 文件。
The best solution is just ignore by closing the file when you don't use it.
最好的解决方案是在不使用文件时关闭文件而忽略它。
回答by Hooman Bahreini
The problem is, you need a xsd schema for packages.config.
问题是,您需要一个用于packages.config.
This is how you can create a schema (I found it here):
这是创建模式的方法(我在这里找到了它):
Open your Config file -> XML -> Create Schema
打开您的配置文件 -> XML -> 创建架构
This would create a packages.xsdfor you, and opens it in Visual Studio:
这将为packages.xsd您创建一个,并在 Visual Studio 中打开它:
In my case, packages.xsdwas created under this path:
就我而言,packages.xsd是在此路径下创建的:
C:\Users\MyUserName\AppData\Local\Temp
C:\Users\MyUserName\AppData\Local\Temp
Now I don't want to reference the packages.xsdfrom a Temp folder, but I want it to be added to my solution and added to source control, so other users can get it... so I copied packages.xsdand pasted it into my solution folder. Then I added the file to my solution:
现在我不想引用packages.xsdTemp 文件夹中的 ,但我希望将它添加到我的解决方案并添加到源代码管理中,以便其他用户可以获取它......所以我将packages.xsd它复制并粘贴到我的解决方案文件夹中。然后我将文件添加到我的解决方案中:
1. Copy packages.xsdin the same folder as your solution
1. 复制packages.xsd到与您的解决方案相同的文件夹中
2. From VS, right click on solution -> Add -> Existing Item...and then add packages.xsd
2. 在 VS 中,右键单击解决方案 -> 添加 -> 现有项目...,然后添加packages.xsd
So, now we have created packages.xsdand added it to the Solution. All we need to do is to tell the config file to use this schema.
所以,现在我们已经创建packages.xsd并将其添加到解决方案中。我们需要做的就是告诉配置文件使用这个模式。
Open the config file, then from the top menu select:
打开配置文件,然后从顶部菜单中选择:
XML -> Schemas...
XML -> 架构...
Add your packages.xsd, and select Use this schema(see below)
添加您的packages.xsd,然后选择使用此架构(见下文)
回答by David Ebbo
This happens because VS doesn't know the schema of this file. Note that this file is more of an implementation detail, and not something you normally need to open directly. Instead, you can use the NuGet dialog to manage the packages installed in a project.
发生这种情况是因为 VS 不知道此文件的架构。请注意,此文件更多是一个实现细节,而不是您通常需要直接打开的内容。相反,您可以使用 NuGet 对话框来管理项目中安装的包。
回答by chuckc
This works and remains even after adding a new package:
即使在添加新包后,这仍然有效并保持:
Add the following !DOCTYPE above the <packages> element:
在 <packages> 元素上方添加以下 !DOCTYPE:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE packages [
<!ELEMENT packages (package*)>
<!ELEMENT package EMPTY>
<!ATTLIST package
id CDATA #REQUIRED
version CDATA #REQUIRED
targetFramework CDATA #REQUIRED
developmentDependency CDATA #IMPLIED>
]>


