Visual studio 2015 nuget package not restoring - visual-studio

I've got a project with multiple nuget projects, when I opened this project with visual studio 2015 I did a nuget restore, but all packages references are still broken. In the packages folder, all the packages have been downloaded. How can I restore the packages? It is important that the versions currently defined stay the same and don't upgrade the packages.
If I unload my project, the references seem good, the package versions match:
<Reference Include="Dapper">
<HintPath>..\packages\Dapper.1.42\lib\net45\Dapper.dll</HintPath>
</Reference>
<Reference Include="EasyNetQ">
<HintPath>..\packages\EasyNetQ.0.49.3.390\lib\net40\EasyNetQ.dll</HintPath>
</Reference>
<Reference Include="FluentScheduler">
<HintPath>..\packages\FluentScheduler.3.1.45\lib\net40\FluentScheduler.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>

First navigate to C:\Users\.dnx\packages and delete all packages from this location.
Next, in VS2015 load your project and in the Package Manager Console run dnu restore (you may have to use the cd command to get into the same directory as your project.json file if it doesn't default you to there)

The .nuget folder was missing. For some sort of reason, committing my .nuget folder from the original solution to the projects SVN, and then updating the broken project SVN fixed the problem.

Related

Binaries are added to /bin without a reference, why?

I am using a custom built NuGet package with a set of binaries from DevExpress. Whenever I build the project from Visual Studio, a lot of "extra" DevExpress binaries, that I have not added a reference too, is also added to the bin folder.
I have installed a DevExpress suite of some sort so it might be that some of the GAC'ed binaries are added, but why ? I do not wish to have these binaries cluttering my bin folder.
VS references:
Bin folder:
Might be that assemblies knows its dependencies. The Assembly Explorer show you which:
In addition to Rolf's answer.
If the reference is set to "local" in the project, the dll's will be moved to the output folder (\bin)
In the project those refenrences will have a <private>True</Private> tag:
fx:
<Reference Include="log4net, Version=2.0.8.0, ...>
<HintPath>..\packages\log4net.2.0.8\lib\net40-full\log4net.dll</HintPath>
<Private>True</Private> <-- HERE
</Reference>

NuGet package reference & version

I tried crawling through the documentation for NuGet and Visual Studio but did not find an exact answer for my question. Also am new to using NuGet.
If I have a packages.config like below:
<packages>
<package id="xxx.SomePackage" version="1.0.1" targetFramework="net452" />
</packages>
And a similar reference in my .csproj for the project:
<Reference Include="xxx.SomePackage, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\xxx.SomePackage.1.0.1\lib\net45\xxx.dll</HintPath>
<Private>True</Private>
</Reference>
Suppose I have a newer version which I want the projects to use namely 1.0.2, should I manually change each csproj/packages.config reference to point to that version or is NuGet smart enough to get and apply only the latest version to my projects ? I have a lot of projects so it's a pain to change for each one.
Note: I read about using SpecificVersion: False. Is that something I can use ?
Note: I also read about "Update-Package -reinstall". Is this the best and preferred method for scenarios like mine ?
should I manually change each csproj/packages.config reference to point to that version or is NuGet smart enough to get and apply only the latest version to my projects ? I have a lot of projects so it's a pain to change for each one.'
No, you don not need to manually change each csproj/packages.config reference to point to that version. NuGet smart enough to get and apply only the latest version to your projects.
You can use the command line Update-Package -Id <package_name> -Version 1.0.2 in the Package Manager Console, without specifying any particular project, Update-Package affects all projects in a solution. See update-package for more detail info.
Alternatively, you can also update all projects via Manager NuGet Packages for Solution. Right click your solution (not project), select Manager NuGet Packages for Solution, switch to Updates tab, choose the package you need to upgrade, then select the projects you want to update the package:
Besides, Update-Package -reinstall is used to reinstall packages, using this command is much easier than removing a package and then trying to locate the same package in the NuGet gallery with the same version. So this command would not update the version of the package.
Hope this helps.

syncfusion.compression.base cannot be downloaded because it is not compatible with any project in the solution

Hi, I was working on a solution using Visual Studio. While restoring the Nuget, i got the error "syncfusion.compression.base" is missing. When I tried downloading the Nuget, it gave the message as shown in screenshot. What shall I do now?
When I tried downloading the Nuget, it gave the message as shown in screenshot. What shall I do now?
You need to figure out which project installed the package before in your solution. You can check it with the package.config file.
After download the package syncfusion.compression.base from nuget.org, we could to know this package only have one assembly for .NET framework 46:
After you figure out which project installed this package, you should check the project type and target framework, make sure the target framework is .NET 46 and above.
Besides, if can not find this package in the package.config or project.json, you may need to check if your project file contains HintPath for this package, like:
<Reference Include="Syncfusion.Compression.Base, Version=15.2460.0.40, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.Compression.Base.15.2460.40\lib\net46\Syncfusion.Compression.Base.dll</HintPath>
<Private>True</Private>
</Reference>
To determine whether the package is what you need, if not, you need delete it in the project file and delete the package in the packages folder.

Is NuGet automatic package restore in Visual Studio 2015 a fairy tale/mythical beast?

I have been trying to figure out why automatic package restore in Visual Studio 2015 doesn't work.
As I understand it there is nothing to do but check a couple of settings. When you build, it looks for missing packages and downloads them automatically.
I have a solution that has 15 individual projects. The majority of them will not compile because of "missing packages".
I do not have any of the legacy NuGet (.nuget folder etc.) in any of these projects and I have the latest and greatest version of NuGet.
Visual Studio simply will not download the missing files. I deleted the solution package folder and it does re-create and download all of the packages when I build, but each individual project still shows missing references.
If I go to the package manager console and issue a
Update-Package -reinstall
then the packages download and everything works. I'm just wonder why it doesn't do this automatically.
It's supposed to right?
NuGet Restore only restores files in the packages directory, but does not restore files inside your project or modify your project.
For example, if there has a package will add some reference dlls or add some content files into your project. After deleting these reference dlls and content files from your project, it will not be added when restoring this package. This will cause the your project could not find the missing pacakges when compile.
So we need use "Update-Package -reinstall" command to force reinstall the package references and content files into project.
Update the example for sharing projects in a team:
Following is my solution structure, the CommDLL project installed some NuGet packages and entire solution is managed by a source control.
I download this solution on another machine from source control use another user account and install another NuGet packages into the CommDLL project. Then use some content from the new installed package and build the project successful. Please make sure the package dlls has been added into your project and it has been set the correct HintPath in .csproj file.
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
Next, I check in this modified project into the source control. Please make sure you the .csproj file and packages.config file are checked in.
Now I get the latest version on another machine to get the modified content. After check out the latest version from source control, the package references are shown with a warning because the project is not compiled, which means the packages are not restored. Please rebuild this project, it will restore the packages for your project (make sure your Visual Studio 2015 has enable "Allow NuGet to download missing packages" and "Automatically check for missing packages during build in Visual Studio" before rebuild this project).

Visual Studio 2015 can't find nuget package references and DLLs in packages folder

I've been given a C# project by someone else. I opened the project and tried to install all the Nuget packages by doing a Update-Package -reinstall.
It downloaded all the packages in the packages folder.
/Projects
/WebApiTest (root folder)
WebApiTest.csproj
WebApiTest.sln
/packages (packages are loaded in this folder)
But the entire project still says that it's missing all the references. I editted the csproj file to see where it tries to load the packages from, and that is:
<ItemGroup>
<Reference Include="Antlr3.Runtime">
<HintPath>packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="EntityFramework">
<HintPath>packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
... etc.
So I assume it starts looking in the same directory as the csproj file is in. In that same directory is also the packages folder that has all the DLL files. So the path seems to be right.
Why is my project still not able to load the references?
This post is starting to get old, but as I have encountered this issue myself and fixed it, I'll share a possible solution.
I had to manually uninstall and re-install the packages by right-clicking on the problematic project, Manage NuGet packages..., then uninstall/reinstall from there.
Be careful on the packages version: be sure to grab the same, in case the project isn't using the latest.
A noticeable effect for me after this procedure is that the paths in the csproj file got updated.
Hope it'll help someone :)
Open up the csproj file for your project in a plain text editor and fix the paths for the DLL's. You may see something like:
<HintPath>packages\etc\etc\etc...</HintPath>
I changed those occurrences to:
<HintPath>..\packages\etc\etc\etc...</HintPath>
I pushed this change from the computer that the project was working fine on and pulled them back down on the bad machine and it was no longer an issue.
Note: This wouldn't be an issue if your project file was in the same folder as your packages folder.
Does NuGet successfully restore the packages from the command line?
Try running this from the command line, from the same folder as your solution:
nuget restore WebApiTest.sln
Note, you may need to fully qualify the execution of nuget (e.g. C:\nuget\nuget.exe), or have it in your path.
You may need to download the NuGet executable, if you haven't already.
If that doesn't work, hopefully it will shed some light on why!
What fixed the missing project references for me was to simply:
Close Visual Studio
Delete the "packages" folder where all the nuget packages are stored (probably at your solution-level or else project-level directory)
Open the solution again in Visual Studio
If you have automatic package restore on, just rebuild, else first restore the nuget packages (from the solution context menu) and then rebuild.

Resources