如何调试(最好在IDE中)MSBuild脚本? [英] How can I debug (preferably in an IDE) an MSBuild script?

查看:187
本文介绍了如何调试(最好在IDE中)MSBuild脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我们的持续集成过程的一部分,我们使用MSBuild,尽管它的功能非常强大,我们可以在其中进行所有的构建,测试和部署(利用一些自定义任务) - 我们发现调试



我发现: http://www.wintellect.com/CS/blogs/jrobbins/archive/2007/12/03 /msbuild-debuggers.aspx ,但不幸的是,该项目似乎已经从Codeplex消失。



有人有任何想法,如果有类似的东西

解决方案



我使用 / v:diagnostic 命令行开关。 MSBuild吐出一些相当冗长的输出。您还可以使用 / fl [n] 命令行开关将详细输出发送到日志文件,而不是控制台,然后使用 / flp [n] (filelogparameter)开关指定详细程度级别,例如 /flp:Verbosity=diagnostic;LogFile=latest_diagnostic.log



您必须从一开始就设计构建脚本,使故障排除更容易。执行以下操作:



尽可能细化每个目标,以便可以单独调用每个目标。



确保您的任务继承自 Microsoft.Build.Utilities.Task 类。它暴露了一个日志属性,它有太多的日志功能。我通常错误地使用 LogMessage(MessageImportance,string,params对象[])。我的调试消息得到 MessageImportance.Low 的消息重要性,因此它们只有在详细模式是诊断时才出现。



使用 System.Diagnostics.Trace.WriteLine 输出太低级别的日志消息。我使用 DebugView 查看这些邮件。



最后,尽量不要在MSBuild脚本本身做很复杂的事情。 MSBuild擅长管理依赖关系,文件列表和运行任务。任何更复杂或高级的应该移动到用您选择的.NET语言编写的自定义任务。这具有使事情更容易调试的额外的好处。当你有代码中的逻辑,你可以使用 System.Diagnostics.Debugger.Launch()方法,这将允许你附加MSBuild到调试器在运行Visual Studio实例(希望已经加载了您的自定义任务)。



祝你好运!


We use MSBuild quite extensively as part of our continuous integration process, and whilst it is incredibly powerful and we can do practically all of our build, test and deployment within it (utilising some custom tasks) - we've found that debugging it using tags is a pain and cannot always provide us with enough information.

I've found: http://www.wintellect.com/CS/blogs/jrobbins/archive/2007/12/03/msbuild-debuggers.aspx, but unfortunately the project seems to have disappeared from Codeplex.

Does anyone have any idea if there is something similar to this available or if there is another way/technique that can be used?

Thanks.

解决方案

I use the /v:diagnostic command-line switch. MSBuild spits out some pretty verbose output. You can also spit the verbose output to a log file instead of the console, using the /fl[n] command line switch, and then use the /flp[n] (filelogparameter) switch to specify the verbosity level, e.g., /flp:Verbosity=diagnostic;LogFile=latest_diagnostic.log

You have to design your build scripts from the start to make troubleshooting easier. Do things like:

Make each target as granular as possible, so you can call each target individually. This helps make the debugging process much quicker.

Make sure your tasks inherit from the Microsoft.Build.Utilities.Task class. It exposes a Log property that has way too many logging functions. I typically err on the side of caution use the LogMessage(MessageImportance,string,params object[]). My debugging messages get a message importance of MessageImportance.Low so they only appear when the verbosity mode is diagnostic.

Use System.Diagnostics.Trace.WriteLine for outputting messages that are are too low-level to log. I use DebugView to look at those messages.

Lastly, try not to do really complicated things in the MSBuild script itself. MSBuild excels at managing dependencies, lists of files, and running tasks. Anything more complicated or advanced should be moved to custom tasks written in your .NET language of choice. This has the added benefit of making things much easier to debug. When you've got your logic in code, you can use System.Diagnostics.Debugger.Launch() method, which will allow you to attach MSBuild to the debugger in a running instance of Visual Studio (hopefully one that has your custom task already loaded).

Good luck!

这篇关于如何调试(最好在IDE中)MSBuild脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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