Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 'packages' element is not declared warning

So in Visual Studio 2017, I get the following warning in the auto-generated packages.config file:

The 'packages' element is not declared.

It is the same issue as here: The 'packages' element is not declared

And here: nuget 'packages' element is not declared warning

The consensus seems to be that this warning can be safely ignored. Moreover, some of the comments suggest that attempts at fixing this can cause other issues and/or be hard to maintain.

For example, one contributor said:

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.

However, the most recent contributor suggested simply changing <packages> to <packages xmlns="urn:packages">. Doing this makes the error go away and I saw no OBVIOUS problem (my experience here is very limited).

However, I don't want to risk causing Nuget problems over a warning that does not need to be addressed. On the other hand, every project created in VS, I'm guessing, will have this error by default, so an easy, safe, and easily maintainable fix would be good to have.

So my bottom line question is: what exactly does changing <packages> to <packages xmlns="urn:packages"> in the packages.config file do, and are there any risks or downsides to doing this?

like image 321
Pennywise Avatar asked Apr 02 '17 18:04

Pennywise


People also ask

How do I restore a NuGet package?

After you enable package restore in Options, you can right-click the solution in Solution Explorer and select Restore NuGet Packages to restore packages anytime. If you enabled automatic restore in Options, Package Restore happens automatically when you create a project from a template or build a project.

Where is package config?

If used, packages. config must be located in a project root. It's automatically created when the first NuGet operation is run, but can also be created manually before running any commands such as nuget restore . Projects that use PackageReference do not use packages.


1 Answers

what exactly does changing <packages> to <packages xmlns="urn:packages"> in the packages.config file do, and are there any risks or downsides to doing this?

Using <packages xmlns="urn:packages"> in the packages.config file adds the schema to the file. The xmlns (namespace) declaration is nothing more than a string in the form of a uniform resource identifier (URI) and this declaration is not required. NuGet uses the <packages> node in packages.config to restore project dependencies as is described in the Schema section of the packages.config reference. This is why Microsoft used <packages> instead of <packages xmlns="urn:packages">.

The packages.config file is auto-generated and can be used by NuGet as-is. There is no need to change the file and there no risks or downsides associated with ignoring the warning.

like image 57
Leo Liu-MSFT Avatar answered Oct 20 '22 07:10

Leo Liu-MSFT