首页 文章

从命令行使用msbuild时缺少nuget包错误

提问于
浏览
7

我正在开发一个silverlight应用程序 . 我们正在使用nuget包,但我们不检查包,并且应该在构建时恢复包 . 该解决方案在visual studio中编译得很好 . 我正在尝试使用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}“构建失败

在执行此步骤之前,我正在进行明确的nuget恢复 .

Exec {C:\ project \ nuget.exe restore $ solutionFile}“恢复失败”

此步骤将传递消息“packages.config中列出的所有软件包”已安装 .

但是当实际构建步骤发生时,构建将失败并显示消息

此项目引用此计算机上缺少的NuGet包 . 启用NuGet Package Restore以下载它们 . 有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105 . 丢失的文件是\ Source \ .nuget \ NuGet.targets .

我正在进行明确的nuget恢复,并且已启用

在Visual Studio中“允许nuget下载丢失的包”,在解决方案级别中“启用nuget包恢复” .

我的nuget.config有“disableSourceControlIntegration”value =“true”

我在stackoverflow中看到了类似的问题,我已经尝试了所有上面建议的解决方案 . 尽管如此,我还是不知道它为什么会失败 .

2 回答

  • 2

    您不需要同时执行 nuget.exe restore 并让MSBuild使用NuGet.targets来恢复NuGet包 . 你应该选择其中一个 .

    我怀疑你的问题是 $rootDir 没有定义,你传递给MSBuild的 SolutionDir 属性是:

    \Source

    在我的项目文件中,我有:

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

    因此,如果 SolutionDir\Source ,则解决方案将无法使用相同的错误消息进行编译 .

  • 2

    在我的,csproj文件不知何故有这个:

    <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'))" />
    

    删除它解决了这个问题 .

相关问题