Nuget.Config not working on solution level

Sanjay Kumar Jha 156 Reputation points
2023-11-08T11:42:22.9066667+00:00

Hi,

I want to download and store NuGet packages in a specific directory at the solution level. I've created a "NuGet.Config" file for this purpose and set the "repositoryPath" to specify the directory location. However, when I attempt to download NuGet packages, they are only saved to the default location at "C:\Users\sanjay.nuget\packages." I'm unsure why the path specified in the NuGet.Config file isn't working as expected. I'm seeking assistance to resolve this issue.

Please find the project:

"https://vemp-my.sharepoint.com/:u:/g/personal/sanjaykumarjha_virtualemployee_com/EalD9ihezidFoYrEdyrsZYwB0eVDWp9m7voimB8X0JYXvw?e=hy11I7"

Thanks,

Sanjay

Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
Developer technologies | Visual Studio | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 34,441 Reputation points Microsoft External Staff
    2023-11-09T10:38:23.1466667+00:00

    Hello @Sanjay Kumar Jha,

    Welcome to Microsoft Q&A forum.

    In short, you can try to add following property in your .csproj file.

    <PropertyGroup>
      <RestorePackagesPath>D:\YourSolutionFolder</RestorePackagesPath>
    </PropertyGroup>
    

    Explanation: I can see that your project targets .NET 7.0. Actually, while using NuGet packages, projects based on .NET is different from projects based on .NET Framework. .NET based projects use PackageReference by default, but .NET Framework based projects use packages.config by default. See this document: Project type support

    By default, PackageReference is used for .NET Core projects, .NET Standard projects, and UWP projects targeting Windows 10 Build 15063 (Creators Update) and later, with the exception of C++ UWP projects. .NET Framework projects support PackageReference, but currently default to packages.config.

    You are using .NET 7.0 project, so by default it uses PackageReference, and as this document: nuget.config reference - repositoryPath says:

    repositoryPath(packages.config only)

    it is expected that it doesn’t work in your .NET 7.0 project.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Sanjay Kumar Jha 156 Reputation points
    2023-11-14T11:42:22.2233333+00:00

    Hi,

    I followed your recommendation to download all NuGet packages in one location. However, I encountered an issue: when I uninstall a NuGet package from my project, the NuGet manager doesn't remove it from the global folder. Why is this happening, and how can it be addressed? Ideally, I'd like the NuGet package to be installed at the specified folder location when I install it and removed from that location when I uninstall it from the project. Your assistance in resolving this matter is greatly appreciated.

    Providing a video file attachment. Kindly download it using the link below.

    Link :"https://vemp-my.sharepoint.com/:v:/g/personal/sanjaykumarjha_virtualemployee_com/Ea57CHWTqutGjFafMmKWyKsB0pxpK_yFB-6JqvXNTVTpZg?nav=eyJyZWZlcnJhbEluZm8iOnsicmVmZXJyYWxBcHAiOiJPbmVEcml2ZUZvckJ1c2luZXNzIiwicmVmZXJyYWxBcHBQbGF0Zm9ybSI6IldlYiIsInJlZmVycmFsTW9kZSI6InZpZXciLCJyZWZlcnJhbFZpZXciOiJNeUZpbGVzTGlua0RpcmVjdCJ9fQ&e=xRy2EW"

    Thanks,

    Sanjay


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.