Zach Smith
Zach Smith

Reputation: 8961

How to define where msbuild looks for packages?

I'm trying to build a solution from command line. This involves 3 steps:

  1. nuget install
  2. nuget restore
  3. msbuild

I am using a NuGet.Config files that specifies where the nuget packages are cached to, and also where the restored packages are added.

The command nuget restore does not work, nor does it provide a helpful error message other than 'the solution can't be built'. Another answer on StackOverflow helpfully recommended to run the msbuild command and see what the error is.

It would seem that files installed via nuget are not found during msbuild (or apparently nuget restore). This is the log from msbuild for every single assembly other than what is found in GAC:

  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.

How can I specify to msbuild where assemblies installed by nuget are? Also.... why is nuget restore failing? The message I get from nuget restore is:

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

using:

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

As far as I can tell, the nuget error output is completely nonsensical. The absolute path C:\<path>\src\<name>.sln absolutely does exist.

Upvotes: 2

Views: 906

Answers (1)

nvoigt
nvoigt

Reputation: 77294

This is a problem that only surfaced after 15.7.0 of Visual Studio / MSBuild.

NuGet already has an open issue for this problem: https://github.com/NuGet/Home/issues/6918

The current workaround is to install .NET 4.7.1 until the problem is fixed, because that will install the missing library in the Global Assembly Cache.

Upvotes: 2

Related Questions