1

Currently when I am installing Nuget Packages it is installing in a folder called "packages" which is exactly in solution directory. But I want this package to be installed under my project location.

Example:

SolutionFolder:
-->ProjectFolder
    -->Project1

I want the package to be installed under "ProjectFolder" location. To do this, I followed the approach suggested in Change installation location of Nuget Package

I added nuget.config file under "SolutionFolder" as below:

<configuration>
  <config>
    <add key="repositoryPath" value="C:\SolutionFolder\ProjectFolder\packages"/>
  </config>
</configuration>

My expectation is something below:

SolutionFolder:
-->ProjectFolder
    -->packages
    -->Project1

But Actual result is as below:

SolutionFolder:
-->packages
-->ProjectFolder
    -->Project1

It is still creating "packages" folder under solution root directory only.

Could some one correct me where I am doing wrong.

ckruczek
  • 2,361
  • 2
  • 20
  • 23
Siva
  • 1,281
  • 2
  • 19
  • 41
  • Did you do this before trying new location: `if you have an existing packages folder underneath your solution root, you will need to delete it before NuGet will place packages in the new location` ? Also did you restarted Visual Studio? – Siva Gopal Oct 05 '17 at 06:52
  • Why dont you just unload package cut it and paste in your project and then press show all files button from solution explorer. –  Oct 05 '17 at 06:54

1 Answers1

1

Add NuGet.CONFIG file next to your solution file with following content :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
    <add key="repositoryPath" value="..\..\NuGetPackages" /><!--in value fill required directory-->
</config>
<packageRestore>
    <!-- Allow NuGet to download missing packages -->
    <add key="enabled" value="True" />
    <!-- Automatically check for missing packages during build in Visual Studio -->
    <add key="automatic" value="True" />
</packageRestore>
<solution>
    <add key="disableSourceControlIntegration" value="false" />
</solution>
</configuration>
Ali Ezzat Odeh
  • 2,093
  • 1
  • 17
  • 17
  • Thanks for your answer, it worked like charm. During build I observed it is checking for restoring of packages if missing any. As per my understanding based on your answer, now it will restore the missing packages to the repository path i have provided in the .config file am i correct? – Siva Oct 05 '17 at 07:40
  • I verified it by deleting the existing package in the repository i have given and try building it and now I observed it is restoring the package to the location I have given as value for "repositoryPath". – Siva Oct 05 '17 at 07:43
  • Ezzar Odeh,The above workaround i did it for a sample application. when I am trying for my own application it is throwing the following error. "Severity Code Description Project File Line Suppression State Error Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.0 ". Could you help me to solve this issue? – Siva Oct 05 '17 at 09:20
  • 1
    Issue resolved by closing and reopening visual studio. – Siva Oct 05 '17 at 09:30
  • I think its permissions issue, check following answer https://stackoverflow.com/a/23672717/5462775 – Ali Ezzat Odeh Oct 05 '17 at 09:30