7

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.

3
  • For S&Gs, copy your nuget.targets file into the root of \Source Commented Jun 27, 2014 at 13:28
  • @Will Thanks fr the input. I copied the .nuget folder to the root directory it dint help. Commented Jun 27, 2014 at 13:37
  • Can you edit and add your full nuget.config file? Should be comparable to this Commented Jun 27, 2014 at 14:01

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

In mine, the csproj file somehow had this:

  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
  <ErrorText>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 {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />

Removing it had solved the problem.

1 Comment

I'm also facing the same issue, where packages restored through command line nuget command(nuget restore "D:\.." ) not getting referenced when I compile the project from command line using MSbuild. How did it get resolve?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.