1

We have a complex solution (22 sub-projects, one of which is a website) that won't build using TFS Build. If I open the solution on the build server the code compiles fine inside of Visual Studio, but if I open a CMD prompt and try MSBUILD piccsserver.sln I get this error:

"C:\TFS2017_agent\_work\4\s\CorePlatform\PICCS\Main\src\piccsserver.sln" 
    (default target) (1) ->
"C:\TFS2017_agent\_work\4\s\CorePlatform\PICCS\Main\src\PICCS_WebHost.metaproj"
 (default target) (24) ->(Build target) ->  ASPNETCOMPILER : error ASPCONFIG: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not mat
ch the assembly reference. (Exception from HRESULT: 0x80131040) [C:\TFS2017_age
nt\_work\4\s\CorePlatform\PICCS\Main\src\PICCS_WebHost.metaproj]

I notice that when I build from within VS and look at the version of NewtonSoft.Json.dll in the website's bin folder, the version is 11.0.1 which is what I expect, but when I build from the command prompt the version is 4.5.11.15520.

What the heck is going on here? Doesn't building from within VS use MSBUILD?

Ben_G
  • 770
  • 2
  • 8
  • 30
  • Even on a single machine, you might have multiple versions of MSBuild, https://blog.lextudio.com/the-rough-history-of-msbuild-cc72a217fa98 While Visual Studio 2017 strictly uses MSBuild 15, your build script might not (especially true for VS2017, as MSBuild 15 would be hard to locate without `vswhere` utility. Be patient and learn the details. – Lex Li Mar 23 '18 at 20:19
  • I just ran msbuild /? from the command prompt that I'm running on (and failing) and it shows as version 15.5.180.51428, so doesn't that mean that I'm running the same version as VS? – Ben_G Mar 23 '18 at 20:33
  • Then you might just hit a second issue. Can you try to run `nuget restore` (for packages.config) or `msbuild /t:restore piccsserver.sln` (for package references) before running the build? VS should restore NuGet packages automatically, but MSBuild command does not. – Lex Li Mar 23 '18 at 20:48
  • when I run that I get Restore: Nothing to do. None of the projects specified contain packages to restore. In VS I've already restored – Ben_G Mar 23 '18 at 23:29

1 Answers1

1

I got it to work. I changed the value of newVersion in the Web.config from 11.0.0.0 to 11.0.1.0. No idea why that stops if from building only from the command-line, but now it builds both in VS and at the command-prompt.

From this:

<dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0." newVersion="11.0.0.0" />
</dependentAssembly>

to this:

<dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0." newVersion="11.0.1.0" />
</dependentAssembly>
Ben_G
  • 770
  • 2
  • 8
  • 30
  • For some obscure reason this solution is also working in my case. I only omitted the last point in oldVersion, otherwise it will not compile. If I look at the call stack the problem is probably caused very deep in EF.Core 2.1 working together with .Net 4.72. Only some projects have this problem. At the moment I don't know why. I also find it strange that EF.Core 2.1 is looking for Newtonsoft.Json version 11.0.0.0 that don't seem to exist. – JRB Aug 03 '18 at 15:02
  • Additional info: This trick also works for newVersion="11.0.2.0" – JRB Aug 03 '18 at 15:19