Why does msbuild fail while building within VS bui

2019-07-23 07:20发布

问题:

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?

回答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>