7
votes

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.

2
For S&Gs, copy your nuget.targets file into the root of \Sourceuser1228
@Will Thanks fr the input. I copied the .nuget folder to the root directory it dint help.sasikt
Can you edit and add your full nuget.config file? Should be comparable to thisuser1228

2 Answers

2
votes

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.

2
votes

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.