You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2019编译旧项目时Fody报错无法加载Microsoft.Build.Framework程序集

Fody编译报错无法加载Microsoft.Build.Framework解决方法

报错详情

Visual Studio 2019编译旧项目时,Fody 1.28.3执行阶段抛出异常,提示找不到版本为15.1.0.0或4.0.0.0的Microsoft.Build.Framework程序集,完整报错信息如下:

3>    Fody (version 1.28.3.0) Executing
3>MSBUILD : error : Fody: An unhandled exception occurred:
3>MSBUILD : error : Exception:
3>MSBUILD : error : Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
3>MSBUILD : error : StackTrace:
3>MSBUILD : error : 
3>MSBUILD : error : Server stack trace: 
3>MSBUILD : error :    at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
3>MSBUILD : error :    at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
3>MSBUILD : error :    at System.Reflection.RuntimeMethodInfo.GetParameters()
3>MSBUILD : error :    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
3>MSBUILD : error : 
3>MSBUILD : error : Exception rethrown at [0]: 
3>MSBUILD : error :    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
3>MSBUILD : error :    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
3>MSBUILD : error :    at IInnerWeaver.set_Logger(ILogger value)
3>MSBUILD : error :    at Processor.ExecuteInOwnAppDomain() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\Fody\Processor.cs:line 146
3>MSBUILD : error :    at Processor.Inner() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\Fody\Processor.cs:line 93
3>MSBUILD : error :    at Processor.Execute() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\Fody\Processor.cs:line 45
3>MSBUILD : error : Source:
3>MSBUILD : error : mscorlib
3>MSBUILD : error : TargetSite:
3>MSBUILD : error : Void GetSignature(Void*, Int32, System.RuntimeFieldHandleInternal, System.IRuntimeMethodInfo, System.RuntimeType)
3>MSBUILD : error : Could not load file or assembly 'Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
3>MSBUILD : error : StackTrace:

问题根因

你使用的Fody 1.28.3是2017年发布的旧版本,仅适配Visual Studio 2017及更早版本的MSBuild环境。Visual Studio 2019自带的MSBuild版本高于15.1,默认不会安装旧版本的Microsoft.Build.Framework程序集,导致旧版Fody执行时找不到依赖抛出异常。

解决方法

  • 升级Fody版本
    这是最推荐的解决方案,直接通过NuGet包管理器将项目中的Fody升级到3.3.5及以上版本,高版本Fody已经完成Visual Studio 2019及更高版本MSBuild的适配,大部分场景下无需修改其他配置即可解决依赖缺失问题。如果项目同时引用了其他Fody插件(如Costura.Fody、PropertyChanged.Fody等),同步升级到对应兼容版本即可。
  • 添加程序集绑定重定向
    如果因为项目历史依赖问题无法升级Fody,可以在项目配置文件(app.config或web.config,没有则新建app.config放在项目根目录)中添加如下绑定重定向规则,将旧版本Microsoft.Build.Framework的请求重定向到Visual Studio 2019自带的高版本:
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-16.0.0.0" newVersion="16.0.0.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    
    注意将newVersion的值替换为你本地Visual Studio 2019安装目录下Microsoft.Build.Framework.dll对应的实际版本号。
  • 安装旧版MSBuild工具
    无需修改项目配置,直接安装Microsoft Build Tools 2015,安装完成后会自动补全4.0版本的Microsoft.Build.Framework依赖,即可正常编译项目。

内容的提问来源于stack exchange,提问作者voltac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 01:30:04