nuget 'packages' element is not declared warning

后端 未结 7 1624
猫巷女王i
猫巷女王i 2020-12-07 10:05

not a showstopper but when using nuget in a project, it creates a packages.config file with this shape


相关标签:
7条回答
  • 2020-12-07 10:40

    This works and remains even after adding a new package:

    Add the following !DOCTYPE above the <packages> element:

    <?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>
    ]>
    
    0 讨论(0)
  • 2020-12-07 10:43

    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.

    The best solution is just ignore by closing the file when you don't use it.

    0 讨论(0)
  • 2020-12-07 10:49

    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)

    • 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's D:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas for me).

    Then, edit <packages> tag in packages.config file (add xmlns attribute):

    <packages xmlns="urn:packages">
    

    Now the warning should disappear (even if packages.config file is open in Visual Studio).

    0 讨论(0)
  • 2020-12-07 10:50

    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.

    0 讨论(0)
  • 2020-12-07 10:51

    You will see it only when the file is open. When you'll close the file in Visual Studio the warnings goes away

    http://nuget.codeplex.com/discussions/261638

    0 讨论(0)
  • 2020-12-07 10:51

    The problem is, you need a xsd schema for packages.config.

    This is how you can create a schema (I found it here):

    Open your Config file -> XML -> Create Schema

    This would create a packages.xsd for you, and opens it in Visual Studio:

    In my case, packages.xsd was created under this path:

    C:\Users\MyUserName\AppData\Local\Temp

    Now I don't want to reference the packages.xsd from 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.xsd and pasted it into my solution folder. Then I added the file to my solution:

    1. Copy packages.xsd in the same folder as your solution

    2. From VS, right click on solution -> Add -> Existing Item... and then add packages.xsd

    So, now we have created packages.xsd and added it to the Solution. All we need to do is to tell the config file to use this schema.

    Open the config file, then from the top menu select:

    XML -> Schemas...

    Add your packages.xsd, and select Use this schema (see below)

    0 讨论(0)
提交回复
热议问题