Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing nuget packages error while using msbuild from command line

Tags:

nuget

msbuild

I am working on a silverlight app. We are using nuget packages but we dont check in the packages and the packages should be restored while building. The solution compiles well in visual studio. I am trying to add a compile task in command line using msbuild

Exec { C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe $slnFile /p:OutputPath=$outputPath /p:Configuration=Release /p:SolutionDir=$rootDir\Source\ /verbosity:minimal /nologo /m:4 } "Build Failed

Before doing this step, I'm doing a nuget restore explicitly.

Exec { C:\project\nuget.exe restore $solutionFile} "restore failed"

This step passes with a message "All packages listed in packages.config" are already installed.

But when the actual build step happens the build fails with the message

This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is \Source\.nuget\NuGet.targets.

I am doing a nuget restore explicitly and I have enabled

"Allow nuget to download missing packages" in visual studio and "Enable nuget package restore" in solution level.

My nuget.config has "disableSourceControlIntegration" value="true"

I have seen similar issues in stackoverflow and I have tried all the above solutions that were suggested. I don't have a clue why it fails in spite of all these.

like image 991
sasikt Avatar asked Jun 27 '14 13:06

sasikt


People also ask

Is it possible to restore a NuGet package from vs command line?

Currently there are no immediate plans to allow restore calls to happen from VS command line. Give your use case we would recommend using NuGet.exe for your restore (MSBuild works the same for Package Reference/ project.json scenarios, but it ignores package.config projects), and then triggering a build like you were doing before.

How do I build a NuGet package in Visual Studio?

Run the msbuild -t:pack command. To build a NuGet package (a .nupkg file) from the project, run the msbuild -t:pack command, which also builds the project automatically: In the Developer command prompt for Visual Studio, type the following command: The output shows the path to the .nupkg file.

Why is my NuGet package missing from my project?

This project references NuGet package (s) that are missing on this computer. Use NuGet Package Restore to download them. The missing file is {name}. This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.

Why am I getting a NuGet installation error when trying to build?

This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.


1 Answers

You do not need to do both the nuget.exe restore and have MSBuild use NuGet.targets to restore the NuGet packages. You should choose one or the other.

I suspect the problem in your case is that $rootDir is not defined and the SolutionDir property you are passing to MSBuild is:

\Source

In my project file I have:

 <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

So if SolutionDir is \Source then the solution will fail to compile with the same error message.

like image 128
Matt Ward Avatar answered Sep 18 '22 00:09

Matt Ward