TFS 2015 Build builds solution and its projects in wrong order (ASP.NET Core Framework 4.6.1)
<p>I have Asp.Net core (Framework 4.6.1) solution with the following structure:</p>

<p>API sln</p>

<p>|-- WebApi.Project_1</p>

<pre><code>     |-- Project_2 (Core library, referencing Framework 4.6.1)
                references Project_4 (Core Library, referencing Framework 4.6.1)
     |-- Project_3 (Core library, referencing Framework 4.6.1)
                 references Project_4 (Core Library, referencing Framework 4.6.1)
</code></pre>

<p>See the "sanitized" project.json files below.</p>

<p>Some notes:</p>

<p>• there is a number of classic (4.6.1 .net) libraries added to the solution but not referenced yet by any other core projects.</p>

<p>• I created the core libraries and manually referenced .net framework 4.6.1 from their json files</p>

<p>•they use x86 platform, specified in project.json -> buildOptions</p>

<p>Everything is built and run OK by using VisualStudio 2015 (either on my local machine or locally on the same build agent server)</p>

<p>The solution build fails when it is built in CI build by TFS 2015 build engine with the following error:</p>

<p><strong><em>"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(265,5): Error: D:\tfsAgent_work\folder\folder\Project_2\error CS0006: metadata file '\folder\folder\bin\debug\net461\Project_4.dll' could not be found"</em></strong></p>

<p>Same error, but for Project_3, referencing Project_4 as well.</p>

<p>By looking at the build log I see that <strong>Project_4 is built after Projects 2 and 3</strong>, thus the file is not there yet.</p>

<p>I tried different options:</p>

<p>•adding the references in project.json</p>

<p>•using Project references</p>

<p>•Solution properties -> Project dependencies...</p>

<p>•manually reorder the projects in API.sln file.</p>

<p>No difference.</p>

<pre><code>**WebApi_Project_1.json:**

 {
  "dependencies": {
    "Project_2": "1.0.0-*",
    "Project_3": "1.0.0-*",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "System.Net.Http": "4.1.0"
  },

 "tools": {
     "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
   },

   "frameworks": {
      "net461": {}
   },

   "buildOptions": {
     "emitEntryPoint": true,
     "preserveCompilationContext": true,
     "platform": "x86",
     "copyToOutput": {
       "include": [
         "Folder/Folder/Folder/*.xsd",
         "Folder/Folder/Folder/*.xml"
       ]
     }
   },

   "publishOptions": {
     "include": [
       "wwwroot",
       "Views",
       "Areas/**/Views",
       "appsettings.json",
       "web.config"
     ]
   },

   "scripts": {
     "postpublish": [ "dotnet publish-iis --publish-folder %     publish:OutputPath% --framework %publish:FullTargetFramework%" ]
   }
 }


 **Project_2.json**

 {
   "dependencies": {
     "Project_4": "1.0.0.0"
   },

   "buildOptions": {"platform": "x86"},

   "frameworks": {
     "net461": {}
     }

   }


**Project_3.json**
{

  "buildOptions": { "platform": "x86" },

  "dependencies": {

    "Project_4": "1.0.0.0"

  },

   "frameworks": {
    "net461": {
      "frameworkAssemblies": {
        "System.Xml": "4.0.0.0"
      }
    }
  }
}


**Project_4.json**

{
  "version": "1.0.0.0",
  "buildOptions": { "platform": "x86" },
  "frameworks": {
    "net461": {}
  }
}
</code></pre>