PostSharp 未在 TeamCity 上构建:找不到程序集 mscorlib

PostSharp not building on TeamCity: Cannot find assembly mscorlib

PostSharp 将在本地开发机器上构建,不会在 TeamCity 服务器上构建,错误是:

unknown error PS0264: Cannot find assembly 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e'.

以下是构建日志的摘录:

[13:38:22][PostSharp30] Merging assembly binding policy files.
[13:38:22][PostSharp30] Executing "C:\ProgramData\PostSharp.0.43\bin.Release\postsharp-net40-x86-native.exe" <REMOVED SENSITIVE INFORMATION>
[13:38:25][PostSharp30] unknown : verbose PS0265: Detailed log for the next error:
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG: Finding reference assembly with binding identity 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e' in the Reference context.
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  Found file 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll', identity='mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089', ProcessorArchitecture=NoPlatform.
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  Reference mismatch for 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll' [PublicKeyMismatch].
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  Found file 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll', identity='mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089', ProcessorArchitecture=NoPlatform.
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  Reference mismatch for 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll' [PublicKeyMismatch].
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  Found file 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll', identity='mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089', ProcessorArchitecture=NoPlatform.
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  Reference mismatch for 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll' [PublicKeyMismatch].
[13:38:25][PostSharp30] unknown : verbose PS0265: LOG:  The assembly 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e, retargetable=yes' was not found.
[13:38:25][PostSharp30] unknown : verbose PS0265: .
[13:38:25][PostSharp30] unknown error PS0264: Cannot find assembly 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e'. [Public key mismatch]. Build your project with detailed verbosity to see the assembly loading log.
[13:38:25][PostSharp30] C:\BuildAgent\work\be9df088c843a629\src\packages\PostSharp.5.0.43\build\PostSharp.targets(314, 5): The process C:\ProgramData\PostSharp.0.43\bin.Release\postsharp-net40-x86-native.exe exited with code 11.
[13:38:25][Step 4/5] Process exited with code 1

更新

比较 C:\ProgramData\PostSharp\InstalledFrameworks 中的文件(本地与构建服务器)后,我可以看到我的本地机器有这些额外的框架:

  <Framework Identifier=".NETFramework" Version="4.7.1">
    <ReferenceAssemblies>
      <Directory Location="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\" />
    </ReferenceAssemblies>
  </Framework>
  <Framework Identifier=".NETPortable" Version="4.0">
    <ReferenceAssemblies>
      <Directory Location="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\" />
    </ReferenceAssemblies>
  </Framework>
  <Framework Identifier=".NETPortable" Version="4.5">
    <ReferenceAssemblies>
      <Directory Location="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\" />
    </ReferenceAssemblies>
  </Framework>
  <Framework Identifier=".NETPortable" Version="4.6">
    <ReferenceAssemblies>
      <Directory Location="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.6\" />
    </ReferenceAssemblies>
  </Framework>
  <Framework Identifier=".NETPortable" Version="5.0">
    <ReferenceAssemblies>
      <Directory Location="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v5.0\" />
    </ReferenceAssemblies>
  </Framework>

生成服务器需要 Microsoft .NET 可移植库参考程序集 4.6:

  1. 下载并安装Microsoft .NET Portable Library Reference Assemblies 4.6
  2. C:\Program Files (x86)\Microsoft .NET Portable Library Reference Assemblies 4.6\PortableReferenceAssemblies.zip提取到C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\

注意:文件夹“.NETPortable”的字符大小写必须符合定义。使用 mkdir 创建以句点符号开头的文件夹。

C:\ProgramData\PostSharp\BindingMaps 从我的本地计算机复制到构建服务器对我有用 (Postsharp 4.2.19)