1

Visual Studio 2017 / ASP.NET Web Application solution.

The default folder structure is as follow:

enter image description here

What I want to achieve is keeping everything (including packages) inside the WebApplication1 folder (except WebApplication1.sln file).

I know about NuGet.Config but unfortunately it seems mandatory to place this file next to the .sln file. I would have preferred to place this file inside of WebApplication1 folder. I would like to have ONLY ONE file outside of the solution folder: the WebApplication1.sln file.

Bronzato
  • 9,438
  • 29
  • 120
  • 212
  • 1
    Possible duplicate of [Is it possible to change the location of packages for NuGet?](https://stackoverflow.com/questions/4092759/is-it-possible-to-change-the-location-of-packages-for-nuget) – Joe Feb 03 '19 at 19:12
  • Not duplicate because not exactly what I want to achieve: I would like to have ONLY ONE file outside of the solution folder: the WebApplication1.sln file. – Bronzato Feb 03 '19 at 19:30

2 Answers2

3

I know about NuGet.Config but unfortunately it seems mandatory to place this file next to the .sln file. I would have preferred to place this file inside of WebApplication1 folder. I would like to have ONLY ONE file outside of the solution folder: the WebApplication1.sln file.

I understand your requirement, you want to have only WebApplication1.sln file outside of the solution folder. But if you are using nuget.config to change the location of packages, this nuget.config file will be placed in a folder outside the solution folder, which is not what you want.

To resolve this issue, you can put this nuget.config file outside the solution folder, which is not necessary to put this file next to the .sln file, for example, you can put this file in the root directory of the C drive with following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="C:\Users\<UserName>\source\repos\WebApplication1\WebApplication1\packages" />
  </config>
</configuration>

Then close your Visual Studio and delete the packages folder in the solution folder, re-open the Visual Studio and open the your solution, right click on the your solution, select restore the nuget packages, all the nuget packages will be place inside the solution folder and the only file outside of the solution folder is the WebApplication1.sln file:

enter image description here

Note: This method has its own limitations, we have to use absolute path in the nuget.config file and this setting will still be work for other solutions.

Besides, you can try to use PackageReference instead of packages.config in project files. With PackageReference, your packages are point to the global package folder C:\Users\<UserName>\.nuget\packages, so that we do not need add a nuget.config file to change the package folder.

To use the PackageReference, go to the Tools->NuGet PackageManager->Package Manage Settings:

enter image description here

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • The solution of putting the ``NuGet.Config`` file at the root directory of C works... But unfortunately it impacts all solutions on the computer. The solution of using the ``PackageReference`` does not works in my case (there is a migration process from packages.config to PackageReference but not yet compatible with ASP.NET). That being said, I mark your answer as accepted because I think for that moment this is the only available solutions. Thanks. – Bronzato Feb 04 '19 at 09:53
1

My understanding of why the visual studio put the package folder next to .sln but outside WebApplication1 folder is, WebApplication1 is a project in the WebApplication1 solution. But one solution can contains multiple projects. In your case the project name happens to be same as the solution name(due to when you create this project and solution in vs). So if you have multiple projects in this solution but want to share some nuget packages, then it make sense for the package folder to be outside the project folder.

Thant's my understanding for why vs has this default setting. Hope that helps.

think3w
  • 11
  • 2