在 InvokeProcess TF 工作流活动中捕获 regsvr32 的输出
我有一个构建流程设置来使用团队构建构建托管解决方案。该解决方案要求在构建解决方案之前向服务器注册一个非托管组件,因为我们通过 COM 与该组件交互。
我用来注册 ComObject 的活动 (InvokeProcess) 看起来像这样
regsvr32.exe /s ComObject.ocx
我用来注销它的活动 (InvokeProcess) 看起来像这样
regsvr32.exe /u /s ComObject.ocx
我还添加了 WriteBuildMessage
和 WriteBuildError
使用 stdOutput 和 errOutput 作为每个操作的消息的 InvokeProcess
活动。我还确保将构建消息重要性设置为高。
据我了解,这应该将标准输出和错误输出重定向到这些日志记录活动中。
只要我不将 MSBuild 的 /maxcpucount
参数设置为大于 1 的值,注册、构建和取消注册就可以正常工作。
一旦我将其设置为大于 1 的值,我们的清理脚本就会在尝试删除有问题的文件时,进程结束失败并显示此错误消息。
Access to the path '...\ComObject.ocx' is denied.'
我认为发生的情况是注销活动无法从服务器注销 ComObject.ocx,因为当 MSBuild 在多个 cpu 上运行时,它尚未完成。然后,当我尝试从构建服务器中删除它时,它仍然在系统中注册,并且会因访问被拒绝错误而失败。
那么如何将 regsvr32 输出获取到 stdOutput 和 errOutput,以便 WriteBuildMessage 和 writeBuildError 活动能够在构建日志中正确显示它。如果我使用不存在的文件调用 regsvr32,我在构建日志中看不到任何内容。
我希望这是有道理的。
更新
这个问题的解决方案来自对 pantelif 解决方案的细微调整。我所做的是在引发异常的 if 块中,我使用此消息作为消息执行 WriteBuildError:
String.Format("ErrorMessage: {0}", New System.ComponentModel.Win32Exception( System.Runtime.InteropServices.Marshal.GetLastWin32Error() ).ToString() )
这允许我从 regsvr32.exe 获取错误并将其写入构建日志。
I have a build process setup to build a managed solution using team build. This solution requires an unmanaged component be registered with the server before we build the solution as we interface with it via COM.
The activity (InvokeProcess) I use to register the ComObject looks something like this
regsvr32.exe /s ComObject.ocx
The activity (InvokeProcess) I use to unregister it looks something like this
regsvr32.exe /u /s ComObject.ocx
I have also added the WriteBuildMessage
and WriteBuildError
to both InvokeProcess
activities using stdOutput and errOutput as the message for each action. I also make sure to set the build message importance to high.
It's my understanding that this should redirect the standard output and error output into these logging activities.
The registrion, build, and unregistrion works just fine as long as I do not set the /maxcpucount
argument of MSBuild to anything greater than 1.
Once I set it to something greater than 1, our cleanup script at the end of the process fails with this error message when attempting to delete the file in question.
Access to the path '...\ComObject.ocx' is denied.'
I think what's happening is that the unregister activity is failing to unregister ComObject.ocx from the server because MSBuild isn't done with it when it's running across multiple cpu's. Then when I get down to try and delete it from the build server, it's still registered with the system and will fail with the access denied error.
So how do I get regsvr32 output to the stdOutput and errOutput so that the WriteBuildMessage and writeBuildError activities will properly display it in the build logs. If I call regsvr32 with a file that doesn't exist, I see nothing in the build log.
I hope this is makes sense.
Update
The solution to this problem came from a minor tweak of pantelif's solution. What I did was in the if block that throws an exception, I do a WriteBuildError using this as the message:
String.Format("ErrorMessage: {0}", New System.ComponentModel.Win32Exception( System.Runtime.InteropServices.Marshal.GetLastWin32Error() ).ToString() )
This allows me to get the error from regsvr32.exe and write it to the build log.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至于你的第一个问题:
我相信通过应用 E.Hofman 此处。
更具体地说,如果您在“InvokeProcess”中构造一个类似于所呈现的序列(图片也来自 Ewald 的帖子):
![enter image此处描述](https://i.sstatic.net/Q6ZLT.png)
&然后分配“WriteBuildMessage”来标记“ErrorMessage”,您可能最终会在生成的构建日志中获得所需的输出。
As for your first question:
I believe it's possible to capture the output, by applying the technique presented by E.Hofman here.
More specifically, if you construct within your 'InvokeProcess' a sequence like presented (pic also from Ewald's post):
![enter image description here](https://i.sstatic.net/Q6ZLT.png)
& then assign 'WriteBuildMessage' to stamp the 'ErrorMessage', you shall probably end up with getting the output you desire in the generated build log.