Rod
Rod

Reputation: 4451

Can the Packages folder be at the project level?

One of my colleagues whose working on another project, was having with the TFS builds. He was getting these errors:

##[error]Unable to find version '12.0.0.1' of package 'Microsoft.ReportViewer.Common.v12'

He contacted me for help (I'm the current TFS Admin). Looking at his repo in TFS I saw that his repo has two Packages folders. One is at the solution level. The other is within the startup project level. Both have NuGet packages within them, although I do see differences in some of the NuGet packages, such as Microsoft.ReportViewer.Common.v12, between the two.

I've looked for other posts here on SO related to NuGet packages. I found this post NuGet issues with packages.config, project references and the solutionwide packages folder, which is helpful, but I've still got a question. That post and this Microsoft document article Install and manage packages in Visual Studio using the NuGet Package Manager leads me to believe that there should only be one Packages folder, which I understand is to be at the solution level. Was it the case that in the past Visual Studio and NuGet put the Packages folder at the project level?

Addendum

Here's a screen shot of the solution, which has a Packages folder at the solution (.sln) level which I highlighted with a red mark, and another Packages folder with within the PharmacyWarehouse project level (.csproj) which I also highlighted with a red mark:

enter image description here

Upvotes: 0

Views: 1907

Answers (1)

Mr Qian
Mr Qian

Reputation: 23715

If my guess on the comment is right, please check these below.

You are right. VS always puts packages folder in the solution folder by default. It is designed by that.

So I think someone has migrated the packages folder into the project folder. And then change hintpath of the referenced dlls on the csproj file manually.

If so, that is the behavior of yourself rather then VS itself. And you have uploaded all packages content from the project level into TFS.

Some points for expansion

However, the location of packages folder can be controlled by a new nuget.config file. Create a file called nuget.config and then put it on any above project level, and then it will act on any projects in a subdirect directory or a lower-level project folder.

You should note that

It can put the packages folder at least on the solution folder or above. And it cannot put the folder into the project folder. See this similar issue.

enter image description here

So that is why I first explain that it is an individual action and the nuget.config file cannot act into the project folder.

The nuegt.config file should be placed at least in the solution folder or above. So this function(add a new nuget.config) cannot control the nuget behavior in the project folder for all projects.

Its content might be these:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <config>
         <add key="repositoryPath" value="packages" />
    </config>
</configuration>

VS supports the custom nuget.config file to control the behavior of nuget. More info, you can refer to this link.

It will make the packages folder under above level\packages. It will get the final new address based on the current address of nuget.config, combined with the value of RepositoryPath. So you have to upload the file at the same time.

As a conclusion

The behavior is caused by someone who modified it. You have to contact with it and try to upload the whole content of the packages folder on TFS and then add a nuget restore task.

Or you can migrate packages folder back to the solution folder. You have to do it on VS IDE. run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console.

Upvotes: 1

Related Questions