While programming if I need to get from a .NET app (not .NET Core app) the list of directories where NuGet stores its packages. Let’s see how to do this.

Next Option is:

In order to achieve this, you need to use the same code and libraries as nuget.exe does:

  1. Install nuget package NuGet.Configuration to your project.
  2. Add using NuGet.Configuration at the top of your file.
  3. Use the following code (which nuget.exe uses itself under the hood)
var settings = Settings.LoadDefaultSettings(null);
Console.WriteLine(SettingsUtility.GetGlobalPackagesFolder(settings));

Check More:

From within the .targets file, you can access the current file’s location using the $(MSBuildThisFileDirectory) property. Assuming the .targets file is in the nuget build folder; you could get to its own package folder using relative paths like this:

<PropertyGroup>
    <ThisPackageDirectory>$(MSBuildThisFileDirectory)..\</ThisPackageDirectory>
    ...

    I hope you enjoyed reading this post. For more information you can check out Microsoft learn.

    For more information you can visit our C# Section for more such posts.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Explore More

    How To Fix Azure Functions Timer Trigger Unable to Start Running Locally with Vs2022 17 2 X Azurite

    Lately my VS2022 (17.2.x) Azure Functions projects started failing to run locally. The local console had errors related to not being able to start any of the Timer Triggers. The

    How can I clear the NuGet package cache using the command line?

    You can do this using Visual Studio menu on UI or by using command. You have two ways to do this. Let’s check: First Option: Let’s move with first option,

    Get TFS to ignore NuGet packages folder

    We have to tell both NuGet and TFS to ignore the packages, because NuGet is trying to do source-control related stuff that it absolutely shouldn’t be doing. So, you have