Missing nuget package error when using msbuild from command line

I am working on a silverlight application. We use nuget packages, but we do not check the packages, and the packages must be restored during construction. The solution compiles well in visual studio. I am trying to add a compiled task on the 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: minimum / nologo / m: 4} "Build failed

Before doing this step, I do nuget recovery explicitly.

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

This step goes with the message "All packages listed in packages.config" are already installed.

But when the actual build step occurs, the build completes with a message

This project refers to NuGet packages that are not available on this computer. Turn on NuGet package recovery to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105 . Invalid file: \ Source \ .nuget \ NuGet.targets.

I am performing nuget recovery explicitly and I turned on

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

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

I saw similar problems in stackoverflow and I tried all of the above solutions that were suggested. I have no clue why he is failing, despite all this.

+6
source share
2 answers

You do not need to perform nuget.exe repair and use MSBuild for NuGet.targets to restore NuGet packages. You must choose one or the other.

I suspect that the problem in your case is that $ rootDir is not defined, but the SolutionDir property that you pass to MSBuild:

\ Source

In my project file, I have:

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

So, if SolutionDir \ Source , then the solution will not be able to compile with the same error message.

+2
source

In my csproj file it was somehow like 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 this problem solved the problem.

+2
source

Source: https://habr.com/ru/post/971419/


All Articles