14
votes

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?

2

2 Answers

21
votes

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.

-2
votes

add a reference to EntityFramework.SqlServer ... 100% tested , I had the same problem and that's what worked for me .