debug MSBuild Task
来源:互联网 发布:优化车间管理办法 编辑:程序博客网 时间:2024/05/18 01:29
(转)如何调试MSBuild中自定义的Task
How to debug MSBuild tasks
(转载:主页为http://www.sedodream.com/default.aspx,里面还包含很多MSBuild相关的挺不错的东西)
A question that comes up pretty frequently is "How can I debug an MSBuild task"? It's actually pretty simple. In this post I will describe how to easily an effectively debug MSBuild tasks that you are creating. In this example I will be demonstrating a task from my open source tasks at www.codeplex.com/Sedodream. The task is one that was contributed by Grant Holliday.
First in the project where your tasks are contained create a folder that will be used to contain sample MSBuid files that can be used to debug the tasks. This is also a good idea, because it will show people how to use your tasks. If you are don't want to mix samples & code in the same project then just make sure in your build you copy the files to the correct locations. In the sample project, which you can download at the bottom, the folder is named Samples. When you add MSBuild files to the folder make sure you set the file to be copied to the output folder as well. See the image below.
By setting this, the file will be copied to the output folder when the project is built. Since it will be in the output folder we can use a relative path to get to the assembly that contains the task. Take a look at the sample MSBuild file for this task.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TaskLocation Condition="$(TaskLocation)==''">$(MSBuildProjectDirectory)/../DebugTask.dll</TaskLocation>
</PropertyGroup>
<UsingTask TaskName="CreateGuid" AssemblyFile="$(TaskLocation)"/>
<Target Name="Example">
<Message Text="Starting example" />
<CreateGuid>
<Output PropertyName="Guid" TaskParameter="Output"/>
</CreateGuid>
<Message Text="Guid: $(Guid)" />
</Target>
</Project>
The line highlighted contains the path to the assembly that contains the task. This path is relative to the location in the output folder, not the source folder. Also another thing to take note, is that we only write to the TaskLocation property if it is empty. This is useful because you can overwrite the location through command line parameters if necessary. But this shouldn't be needed for what we are trying to accomplish here.
After you create the sample, build the solution. And open a command prompt to verify that it works. Here is a sample of the result of this project file.
Once you've verified that that MSBuild file works then you can right click on the project that contains your task, and select properties. From there go to the debug tab. What we want to do is start the msbuild.exe executable on that sample project file. To do this fill in the full path to it in the Start External program text box, i.e. 'C:/WINDOWS/Microsoft.NET/Framework/v3.5/MSBuild.exe'. In the command line arguments you should pass the name of the project file followed by any msbuild parameters. Typically I will attach a file logger to the process. Finally you should set the working directory to the folder containing the sample. The result should look something like the image shown below.
Following this set a break point in your task, set the project as the startup project and hit F5! Another thing to take note of is that these properties are stored in the .user file so it shouldn't affect any other developers on your team.
Below is the link containing a simple solution that was used here.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/llmlx/archive/2008/12/10/3490290.aspx
- debug MSBuild Task
- DEBUG in background task
- MsBuild
- MSBuild
- msbuild
- 一个使用MSBuild Task自动编译部署的例子
- (转)如何调试MSBuild中自定义的Task
- 浅谈VS编译自定义编译任务—MSBuild Task(csproject)
- 浅谈VS编译自定义编译任务—MSBuild Task(csproject)
- Msbuild Error:指定的配置Debug|MCD无效
- 在myeclipse中Debug自定义的ant task
- MSBuild入门
- MSBUILD全过程
- 学习MSBuild
- MSBuild入门
- MSBuild入门
- MSBuild基本概念
- MSBuild 概述
- 职业生涯12个最致命想法
- Ycnd 累积更新版本及多媒体组件已发布!
- Android移植之文件系统总结
- JS_小工具_自己写了一个画像素画的小工具
- 职业生涯规划基本步骤
- debug MSBuild Task
- 10句职场不败的经典名言
- error C2018: unknown character '0xa1'
- 从经典故事中轻松领悟管理
- 关于初始化C++类成员
- 划亮员工精神火柴6法则
- December, 28
- 字符设备驱动 架构分析
- Android init 启动过程分析