0

Let's say I have a solution called MyFirstSolution and inside I have project with name MyFirstProject. Inside that project I'm installing nuget packages like Dapper, EntityFramework etc...

How things should work: packages folder should be created into the folder MyFirstSolution and inside should be downloaded and installer all nuget packages referenced into the project.

The problem I'm having is that the packages folder is not created and the nuget packages are downloaded one level above the MyFirstSolution folder into some folder called XYZHelper.

When I download a solution from some repository nuget packages are restored to that same folder, not to the solution itself and references in csproj file says that they should be in solutionFolder\packages so all of my projects don't build.

If I copy the packages manually to the folder that they should be, it's all good but after every build a copy is made into that XYZHelper folder.

I don't have any postbuild events or anything like it configured into the projects. It is something with the visual studio I guess, but I can't figure out what.

6
  • can you please be more specific. One interpretation of your question is you're describing exactly how NuGet and the .NET build system works normally. I'm not sure if you're asking about that, or something else. Commented Jun 13, 2019 at 13:06
  • I've edited the question with much more details Commented Jun 13, 2019 at 13:35
  • is the sln-file at the same level as the csproj ? Commented Jun 13, 2019 at 13:39
  • The solution file is in the solution folder, and for each project inside there is a folder and in that folder is the csproj file Commented Jun 13, 2019 at 13:44
  • "When I download a solution from some repository" Talk to the owner of that repo and ask him/her to fix that. Commented Jun 13, 2019 at 16:44

3 Answers 3

1

The solution packages folder can be changed with a nuget.config (the setting name is called repositoryPath). So, check for nuget.config files that might be setting this value. You can get an exact list of nuget.config files used by a restore by downloading nuget.exe from nuget.org/downloads and running nuget restore MyFirstSolution.sln. Near the end of the output it will list every nuget.config file that was read.

When there is no config file that changes the solution packages folder (repository path), it always defaults to a subdirectory named packages in the same directory as the .sln file. The only way I know of to change this location for packages.config projects is with a nuget.config file, so I feel confident you should be able to solve it by finding the right config file.

Sign up to request clarification or add additional context in comments.

Comments

1

How things should work: packages folder should be created into the folder MyFirstSolution and inside should be downloaded and installer all nuget packages referenced into the project.

Hi Stdfan, not sure about your VS version. But for VS2015 and earlier versions, the nuget packages are controlled by packages.config file. And things should work like what you mentioned.

But for VS2017 and VS2019, they have two methods to manage nuget: Packages.config and PackageReference. And for PackageReference format, the packages are stored in C:\Users\xxx\.nuget\packages. So if your vs version is VS2017 or VS2019, you can try if changing the format to PackageReference help resolve this issue.

The problem I'm having is that the packages folder is not created and the nuget packages are downloaded one level above the MyFirstSolution folder into some folder called XYZHelper.

Direction1:

Like zivkan suggested,I also think something affects the restore process.Normal for Packages.config format, the folders would be stored in packages folder. But according to this document, we can customize nuget.config file to control nuget behavior. So please check locations where nuget.config exists,there might be some changes in the nuget.config for computer or some settings in nuget.config for users which causes this issue.(The nuget.config for user won't exist unless we create it there)

Direction2:

When I download a solution from some repository nuget packages are restored to that same folder

As the restore process is invisible in build output, so there is possibility that the nuget restore works well, but something in build process move the content of packages folder into XYZhelper.

Check customize your build. Please check your directory structure for the Directory.build.xx file, it can affect your build process if it exists in any folder of the structure: C:\xxx\lancel\source\repos\

I don't have any postbuild events or anything like it configured into the projects. It is something with the visual studio I guess, but I can't figure out what.

This is not about VS normal settings. I think some custom file causes this issue(no matter nuget.config or directory.build.xxx), and please check if you've installed any third-party software or vs extension. Try close vs, delete the .vs, bin and obj folders and then run vs as safe mode.

Comments

0

Target folder of nuget packages can also be set using the envirenment variable NUGET_PACKAGES.
And you can do this in your existing project-file like this:

<Project Sdk="Microsoft.NET.Sdk"> ... <Target Name="NugetPublicfolder" BeforeTargets="PreBuildEvent"> <Exec Command="SET NUGET_PACKAGES=C:\MyProjectA\libraries\"/> </Target> ... </Project> 

Now when you build/publish the project the libraries will be placed in C:\MyProjectA\libraries\

Actually the nuget packages are first downloaded to the socalled http-cache folder (%userprofile%\AppData\Local\NuGet\v3-cache), where it will be extacted from to the above folder (which is called the globalPackagesFolder folder)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.