1
votes

I have a solution in Visual Studio 2015 that uses several NuGet packages. When I build in Visual Studio 2015, the packages are restored properly and the build succeeds. However, when I push that same project to Visual Studio Online, even though I have "Restore NuGet Packages" checked, the build fails because MSBuild cannot find the referenced binary.

I have looked at the build log and see that my packages are all being restored. Why, even though the package is restored, is the referenced binary not found during the build?

2

2 Answers

5
votes

I found that the problem was not in the NuGet package restore, but in the way that the hint path was written in my .csproj file. To the fix the problem, change the hint path to point to the solution directory using the $(SolutionDir) variable.

For example, the NuGet restore pulled the Microsoft.WindowsAzure.Storage.dll binary, but it could not be found on the build of the project. To fix this, I had to open the .csproj, find the reference to the dll, and change the path from

..\packages\WindowsAzure.Storage.6.1.0\lib\net40\Microsoft.WindowsAzure.Storage.dll

-- to --

$(SolutionDir)\packages\WindowsAzure.Storage.6.1.0\lib\net40\Microsoft.WindowsAzure.Storage.dll

By using the $(SolutionDir) variable, Visual Studio Team Services was able to find my referenced dll and build my project properly.

0
votes

You might also consider checking if the file packages.config, which surely resides on you local system, also gets checked in and is under version control.

First, you might want to see if it's present at the build server (image below is from VS Team Services but it's the same general idea in on-site environment.

Secondly, verify that the file's under version control. As a test, see if it appears under Pending Changes if you add a package.

I made a project with a working build start to fail when I added nUnit. Then, as I checked in the package.config file, it started to restore the packages on the server. When I removed the file from the server, the builds starter to fail again. Details are described in this post.

enter image description here