none
MSBuild unable to locate NuGet references

    Question

  • I have a C# VS2010 solution with numerous NuGet references across the various projects. This compiles fine in VS but when running MSbuild from either the command line or as part of my buildserver task, it fails to find the assemblies referenced in the NuGet packages at ../packages (which is all present and correct)

    The references in the .csproj file are;

    <Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <Private>True</Private>
      <HintPath>..\packages\AspNetMvc.4.0.20126.16343\lib\net40\System.Web.Mvc.dll</HintPath>
    </Reference>

    The MSBuild errors;

    SupplyMonthListBuilder.cs(25,24): error CS0246: The type or namespace name 'SelectList' could not be found (are you missing a using directive or an assembly reference?) [C:\TeamCity\buildAgent\work\8519b8ae30891e59\Fleet\Shared\Shared.csproj]

    Monday, March 19, 2012 2:08 PM

Answers

  • As a test, I created a new MVC4 project (which has lots of '../packages' NuGet references) in Visual Studio and copied it to my build server (which has nothing in the GAC except Framework v4.0) and it managed to resolve the references fine and compile

    /reference:C:\Users\Administrator\Desktop\ConsoleApplication1\packages\System.Json.4.0.20126.16343\lib\net40\System.Json.dll

    So from this it seems my 'real' MVC4 project has something defined in it which is stopping the resolution of assemblies in ../packages.

     
      Primary reference "System.Json, Version=4.0.0.0, Culture=neutral, PublicKeyTo
      ken=31bf3856ad364e35, processorArchitecture=MSIL".
    c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
     warning MSB3245: Could not resolve this reference. Could not locate the assemb
    ly "System.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364
    e35, processorArchitecture=MSIL". Check to make sure the assembly exists on dis
    k. If this reference is required by your code, you may get compilation errors.
    [C:\TeamCity\buildAgent\work\8519b8ae30891e59\Fleet\Shared\FleetShared.csproj]
              For SearchPath "{HintPathFromItem}".
              Considered "..\packages\System.Json.4.0.20126.16343\lib\net40\System.
      Json.dll", but it didn't exist.

    EDIT: I think I've found the problem. My referenced projects aren't in the main solution directory so '../packages' is not correct for them.
    Monday, March 26, 2012 11:42 AM

All replies

  • Hi thecapsaicinkid,
    Please try to explicitly specify the build orders in Visual Studio and check if it works.

    When msbuild builds sln file, it constructs a msbuild project in memory. In order to view it, please follow the instructions in blog: http://weblogs.asp.net/kdente/archive/2005/06/05/410432.aspx
    In addition , Visual Studio is a bit more lenient with respect to references than MSBuild is. Take a look at a previous post at http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/f01c7f6a-de46-406b-a377-5e7cb5af6bd2.
    Reference:
    Compiler Error CS0246
    http://msdn.microsoft.com/en-us/library/w7xf6dxs.aspx


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, March 21, 2012 7:53 AM
  • Hi, I'm not trying to build a solution, just a project. Even if I try to build a project which has just references to NuGet packaged assemblies (default MVC4 project for example has references to MVC.dll and EntityFramework.dll) and not other projects, it still fails.

    Wednesday, March 21, 2012 2:28 PM
  • Hi thecapsaicinkid,

    If you just create a project which doesn't reference to NuGet packaged assemblies, see whether this issue still remains.

    Maybe this issue only caused by the NutGet packaged assmeblies.

    Thank you for your understanding!


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 26, 2012 7:29 AM
  • As a test, I created a new MVC4 project (which has lots of '../packages' NuGet references) in Visual Studio and copied it to my build server (which has nothing in the GAC except Framework v4.0) and it managed to resolve the references fine and compile

    /reference:C:\Users\Administrator\Desktop\ConsoleApplication1\packages\System.Json.4.0.20126.16343\lib\net40\System.Json.dll

    So from this it seems my 'real' MVC4 project has something defined in it which is stopping the resolution of assemblies in ../packages.

     
      Primary reference "System.Json, Version=4.0.0.0, Culture=neutral, PublicKeyTo
      ken=31bf3856ad364e35, processorArchitecture=MSIL".
    c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
     warning MSB3245: Could not resolve this reference. Could not locate the assemb
    ly "System.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364
    e35, processorArchitecture=MSIL". Check to make sure the assembly exists on dis
    k. If this reference is required by your code, you may get compilation errors.
    [C:\TeamCity\buildAgent\work\8519b8ae30891e59\Fleet\Shared\FleetShared.csproj]
              For SearchPath "{HintPathFromItem}".
              Considered "..\packages\System.Json.4.0.20126.16343\lib\net40\System.
      Json.dll", but it didn't exist.

    EDIT: I think I've found the problem. My referenced projects aren't in the main solution directory so '../packages' is not correct for them.
    Monday, March 26, 2012 11:42 AM