严重性 代码 说明 项目 文件 行 禁止显示状态 错误 “SCTask”任务意外失败。 System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 系统找不到指定的文件。 File name: 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 系统找不到指定的文件。 File name: 'Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
解决方案: 我发现一个解决方法似乎可以解决问题,至少在我的环境中运行VS 2017 Professional 15.5.2和Entity Framework 6.1.1。
将DLL(几个相关的)安装到GAC(全局程序集缓存)中,问题就会消失。
按照以下次序:
1-关闭所有正在运行的Visual Studio 2017实例
2-启动Visual Studio 2017开发人员命令提示符
3-键入以下命令(将Enterprise替换为Enterprise或Community,或者相应地调整路径):
gacutil /i "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll"
gacutil /i "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.dll"
gacutil /i "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Engine.dll"
gacutil /i "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Conversion.Core.dll"
gacutil /i "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll"
gacutil /i "D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll"
4-重新启动Visual Studio 2017
实际上,当.NET试图加载一个DLL时,GAC将(在大多数情况下)被赋予优先权,并且FileNotFoundException将会消失,因为您的DLL现在将通过GAC解决。