.NET Core 构建错误:错误 MSB4062 Microsoft.Build.Tasks.ResolveComReference [英] .NET Core error on build: error MSB4062 Microsoft.Build.Tasks.ResolveComReference

查看:32
本文介绍了.NET Core 构建错误:错误 MSB4062 Microsoft.Build.Tasks.ResolveComReference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 .net 核心网络应用程序(针对 net461).该应用程序需要引用一个 COM dll.

I'm working on a .net core web app (targeting net461). The app needs to reference a COM dll.

我添加了 COM 引用,该应用程序仍在我的开发机器上构建.但是,在构建服务器上它无法构建并出现此错误:

I added the COM reference and the app still builds on my dev machine. However, on the build server it fails to build with this error:

C:Program Files (x86)dotnetsdk2.0.0Microsoft.Common.CurrentVersion.targets(2604,5):错误 MSB4062:Microsoft.Build.Tasks.ResolveComReference"任务无法从程序集 Microsoft.Build.Tasks.Core

搜索了一下之后,这似乎是一个非常罕见的错误.任何人都知道错误是什么和/或如何修复它?

After searching a bit, it seems like it's a pretty uncommon error. Anyone know what the error is and/or how to fix it?

更新:似乎 dotnet CLI 不支持 COM 引用.Visual Studio 直接在幕后使用 msbuild,但在构建服务器上,我使用的是 dotnet CLI 命令.

UPDATE: Seems like the dotnet CLI does not support COM references. Visual Studio uses msbuild directly behind the scenes, but on the build server, I was using the dotnet CLI commands.

解决方法:

  1. 引用 COM dll 并重建.Visual Studio 将生成互操作dll.它将被命名为 Interop.MyComDLL.dll.它位于构建输出目录中.
  2. 将生成的 Interop dll 复制到应用程序中的某个位置(我只是在根应用程序级别使用了/dlls 文件夹).
  3. 删除 COM dll 引用.
  4. 向 Interop dll 添加直接引用(依赖项 > 添加引用... > 在 Visual Studio 中浏览)

推荐答案

如果您尝试使用与构建服务器上相同的命令构建它,它也会在开发人员机器上失败,例如

It should also fail on developer machine if you try to build it using the same command as on build server, e.g.

dotnet.exe build Solution.sln --configuration Release --no-incremental

VS 使用 msbuild 构建解决方案,这是一种不同的方式.

VS building solution using msbuild, it's a different way.

这篇关于.NET Core 构建错误:错误 MSB4062 Microsoft.Build.Tasks.ResolveComReference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆