Search code examples
c#.netvisual-studionuget

NuGet package is not being installed when reading from TFS


We are using Visual Studio 2019 and we have a solution that has a references to some NuGet packages either from nuget.org or from our private server we are managing the solution with packages.config management, the problem is there is one ASP.NET project in that solution that does not install any of the required packages(in our case it misses the NewtonSoft.json), and installs all the other ones correctly, even though we have packages restore enabled, and there are other ASP.Net projects in the solution that install the Newtonsoft package correctly, but each time you read the last version of the solution from zero (in the case you delete the local solution and re-read it) from the TFS, you need to install the Newtonsoft.json manually for that project specifically.

PS: it's a problem that can be solved in 5 min every time but I know something is wrong and I have been trying to understand what is it, I don't want to solve it localy, but I need a solution the resolve it on the TFS level, so please help me if you can or if you know any other questions here that can help, please guide me through (if I didn't see it already).

My NuGet.Config document:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
        <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
        <add key="MxNuget" value="our server path" />
    </packageSources>
    <activePackageSource>
        <add key="All"
             value="(Aggregate source)" />
    </activePackageSource>
    <packageRestore>
        <add key="enabled" value="true" />
        <add key="automatic" value="true" />
    </packageRestore>
<solution>
    <add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>

the error we are getting is the following:

The name 'Newtonsoft' does not exist in the current context.

Solution

  • The problem I was having was because the TFS was not restoring all the packages needed because when he sees the Folder 'Packages' in the solution he just check if the package is inside, and when he is done, the version that he found and the one on the local machine may be different and that was causing the problem, so I wanted to delete my packages folder on the TFS but I couldn't find it. For that I installed a package in my solution which adds .tfignore to the .nuget folder in the solution directory, and that last file tells the TFS to ignore the packages file on the server and restor them always.

    Questions that were useful:

    1 - Tfs Can't restore Nuget packages.

    2- NuGet Packages are missing

    3- External: Missing Nuget Packages on TFS Build Server


    I resolved the problem by following the steps:

    1. installed the package DisableSourceControlIntegration to the project that was missing the Newtonsoft.json NuGet.

    2. Unified all the versions of NewtonSoft.json on the projects to which my ASP.Net project has a reference. (I think that was the main problem because I had them unified before but I updated the whole group with their config files).

    3. In the visual studio, open Tools --> Nuget package manager --> package manager setting and make sure that the Packages.config is selected as the format of managing the NuGet packages.

    4. deleted all the packages cash.

    5. Re-compiled the solution.

    6. Pushed to the TFS.