如何定义msbuild查找包的位置?

时间:2018-05-08 15:17:11

标签: msbuild visual-studio-2017 nuget

我试图从命令行构建解决方案。这涉及3个步骤:

  1. nuget install
  2. nuget restore
  3. msbuild
  4. 我正在使用NuGet.Config文件来指定nuget软件包的缓存位置,以及添加已恢复软件包的位置。

    命令nuget restore不起作用,除了&#39之外,它也不会提供有用的错误消息。解决方案无法构建'。有关StackOverflow的另一个答案有助于运行msbuild命令并查看错误是什么。

    nuget(或显然msbuild)期间,似乎找不到通过nuget restore安装的文件。对于除GAC中的内容之外的每个程序集,这是msbuild的日志:

      Primary reference "NTRPRS.NLog.Slack".
    C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "NTRPRS.NLog.Slack". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Avesta\Services\Dashboard\src\Avesta.DashboardService.csproj]
              For SearchPath "{HintPathFromItem}".
              Considered "..\..\..\..\AppData\Roaming\NuGet\packages\NTRPRS.NLog.Slack.5.0.4\lib\net45\NTRPRS.NLog.Slack.dll", but it didn't exist.
              For SearchPath "{TargetFrameworkDirectory}".
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\NTRPRS.NLog.Slack.exe", but it didn't exist.
              For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.5,AssemblyFoldersEx}".
              Considered AssemblyFoldersEx locations.
              For SearchPath "{AssemblyFolders}".
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\130\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\130\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\130\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft SQL Server\130\SDK\Assemblies\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft SQL Server\130\SDK\Assemblies\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft SQL Server\130\SDK\Assemblies\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files\IIS\Microsoft Web Deploy V3\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\NTRPRS.NLog.Slack.exe", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "C:\Program Files (x86)\Microsoft.NET\ADOMD.NET\140\NTRPRS.NLog.Slack.exe", but it didn't exist.
              For SearchPath "{GAC}".
              Considered "NTRPRS.NLog.Slack", which was not found in the GAC.
              For SearchPath "{RawFileName}".
              Considered treating "NTRPRS.NLog.Slack" as a file name, but it didn't exist.
              For SearchPath "bin\Debug\".
              Considered "bin\Debug\NTRPRS.NLog.Slack.winmd", but it didn't exist.
              Considered "bin\Debug\NTRPRS.NLog.Slack.dll", but it didn't exist.
              Considered "bin\Debug\NTRPRS.NLog.Slack.exe", but it didn't exist.
    

    如何指定由nuget安装的程序集的msbuild?另外......为什么nuget恢复失败?我从nuget restore收到的消息是:

    C:\<path>\src>nuget restore
    Error parsing solution file at C:\<path>\src\<name>.sln: Exception has been thrown by the target of an invocation.
    The project file could not be loaded. Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
    The system cannot find the file specified.  C:\<path>\src\<name>.sln
    

    使用:

    MSBuild auto-detection: using msbuild version '15.7.177.53362' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'.
    

    据我所知,nuget错误输出完全没有意义。绝对路径C:\<path>\src\<name>.sln绝对存在。

1 个答案:

答案 0 :(得分:2)

这是一个仅在15.7.0的Visual Studio / MSBuild之后出现的问题。

NuGet已针对此问题提出了一个未解决的问题:https://github.com/NuGet/Home/issues/6918

当前的解决方法是在问题得到解决之前安装.NET 4.7.1,因为这将在全局程序集缓存中安装缺少的库。