MSBuild 任务失败 - 未在单线程公寓中运行

发布于 2024-09-29 04:58:19 字数 852 浏览 1 评论 0原文

我有一个发送电子邮件的自定义 MsBuild 任务(在发送电子邮件之类的格式化内容时执行一些特殊的操作)。

背景

使用 TFS 2008

构建服务器是一台使用 TeamBuild 2008 的独立计算机。

此自定义任务过去工作正常,直到我在构建计算机上安装 .Net 4.0 并设置构建服务以使用新版本的MSBuild(通过将 MSBuildPath 属性设置为 c:\Windows\Microsoft.NET\Framework\v4.0.21006,将 Team Build 2008 配置为使用 MSBuild 4.0 而不是 MSBuild 3.5)

我收到的错误是:

"...\TFSBuild.proj" (EndToEndIteration target) (1) -> (EmailResults target) -> ...\BuildType\TFSBuild.proj(386,5): error : SendEmailTask failed: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.

SendEmailTask​​ 使用SmtpClient 发送电子邮件。 (我怀疑 SmtpClient 正在使用一些引发此错误的底层 ActiveX 对象)。

如何让 MsBuild 在 STA 环境中调用自定义任务?

I have a custom MsBuild task that sends an email (does some special stuff while sending the email -like formatting content).

Background:

Using TFS 2008

Build server is a separate machine using TeamBuild 2008.

This custom task used to work fine until I installed .Net 4.0 on the build machine and setup the build service to use the new version of MSBuild (Configured Team Build 2008 to use MSBuild 4.0 instead of MSBuild 3.5 by setting the MSBuildPath property to c:\Windows\Microsoft.NET\Framework\v4.0.21006)

The error that I get is:

"...\TFSBuild.proj" (EndToEndIteration target) (1) -> (EmailResults target) -> ...\BuildType\TFSBuild.proj(386,5): error : SendEmailTask failed: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.

The SendEmailTask uses SmtpClient to send an email. (my suspicion is that the SmtpClient is using some underlying ActiveX object which is throwing this error).

How do I get MsBuild to invoke the custom task in a STA environment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野侃 2024-10-06 04:58:19

您的构建任务正在尝试启动 Internet Explorer。是的,它需要一个 STA 线程,不,您无法从 MSBuild.exe 中获得一个线程

。我完全不清楚如何从 SmtpClient 转到 Internet Explorer。使用 HTML 正文或某种附件对我来说听起来很遥远。让您的构建任务启动一个执行该工作的程序至少应该为您提供更好的诊断。

Your build task is trying to start Internet Explorer. Yes, it needs an STA thread, and no, you can't get one out of MSBuild.exe

How you got from SmtpClient to Internet Explorer is completely unclear to me. Using an HTML body or some kind an attachment sounds all pretty remote to me. Having your build task start a program that does the job instead at least ought to give you a better diagnostic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文