Search code examples
tfsmsbuildnugettfsbuild

How to restore nuget packages referenced by PCL (with project.json) on TFS 2013 Build Server


What I Need

I'm trying to build PCL library (with project.json) on TFS 2013 Build Server with VS2015 Update1 installed.

What's the problem

Nuget packages (Mirosoft.NETCore and Microsoft.NETCore.Portable.Compatibility) for the PCL library are not restored.

I'm getting errors like

 Properties\AssemblyInfo.cs (9): The type or namespace name 'AssemblyTitle' could not be found (are you missing a using directive or an assembly reference?)
 Properties\AssemblyInfo.cs (17): Predefined type 'System.String' is not defined or imported
 Properties\AssemblyInfo.cs (29): Predefined type 'System.String' is not defined or imported
 Properties\AssemblyInfo.cs (30): Predefined type 'System.String' is not defined or imported

 C:\Users\MHABLDSvc\AppData\Local\Temp\.NETPortable,Version=v5.0.AssemblyAttributes.cs (4): Predefined type 'System.String' is not defined or imported
 C:\Users\MHABLDSvc\AppData\Local\Temp\.NETPortable,Version=v5.0.AssemblyAttributes.cs (4): The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?)
 C:\Users\MHABLDSvc\AppData\Local\Temp\.NETPortable,Version=v5.0.AssemblyAttributes.cs (4): Predefined type 'System.String' is not defined or imported

What I've tried:

The first attempt was to enable Automatic Package Restore in $slnDir$.nuget\nuget.exe. This works in visual studio, but not during the TFS Build.

So I changed the TFS build definition to build my build.proj instead of .sln file.

It restores nuget packages for .NET 4.6 class library, but not for my PCL library

build.proj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
         DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name="UnsetReadonly">
    <Exec Command="attrib -r &quot;$(SourceDir)*.*&quot; /s"/>
  </Target>

  <Target Name="RestorePackages" DependsOnTargets="UnsetReadonly">
    <Exec Command="&quot;$(MSBuildThisFileDirectory)Nuget-Publishing\NuGet.exe&quot; restore &quot;%(Solution.Identity)&quot;" />
  </Target>

  <Target Name="Clean">
    <MSBuild Targets="Clean" 
             Projects="@(Solution)" />
  </Target>



  <Target Name="Build" DependsOnTargets="RestorePackages">

    <MSBuild Targets="Build" 
             Projects="@(Solution)"
             UseResultsCache="True" StopOnFirstFailure="true" Properties="Verbosity=Minimal"  />

  </Target>    
</Project>

nuget.exe restore says: All packages listed in packages.config are already installed. However, my problem are packaged from project.json


Solution

  • This was resolved in NuGet 3.4.

    Related issue:

    Cannot install NuGet package depending on Microsoft.NETCore into .NET Framework 4.6 console application project #1883

    Not sure but this commit on project.json might have fixed it.