How do I debug a task inside of Visual Studio?
Two options:
*
(Recommended) Use the Create New Task template which can be found here:
NOT YET UPLOADED * Follow the steps listed below.
Note: this is already done for you if you use the above template
Step 1 - Create a dummy project file that registers your task
The best way to debug a task in the IDE is to have a project file (call it dummy project) which actually registers and calls your task through the
MSBuild engine. This can be as simple as:
* Add a new XML project item to your existing project (the one that defines the task)
* Mark that project element as "Copy to Output Directory" true
* Type a simple project which uses your task in that XML project item
Add a new XML project item to your existing project
http://alexkipman.members.winisp.net/channel9wikiimages/wikiFAQDebugginATask.jpg
Mark that project element as "Copy to Output Directory" true
http://alexkipman.members.winisp.net/channel9wikiimages/wikiFAQDebugginATask2.jpg
Type a simple project which uses your task in that XML project item
<Project xmlns="http://schemas.microsoft.com" DefaultTargets="A">
[<UsingTask] TaskName="MyFoobarTask" AssemblyFile="MyFoobarTaskAssembly.dll" />
<Target Name="A" >
[<MyFoobarTask] Input1="..." Input2="..." InputN="..." />
</Target>
</Project>
Step 2 - Set start action to "Start External Program"
A task is just a unit of
MSBuild and as such it is not really debuggible (it's just a .net library). The thing you really want to debug is the task you are authoring running through the
MSBuild Engine. As such you need to make sure you are starting to debug the
MSBuild Engine and not the task itself. You do this by simply pointing the start action to your
MSBuild location on disk. Do a "where MSBuild.exe" to find out where you are referencing
MSBuild from. In a standard layout install of Visual Studio
MSBuild is located under %windir%\Microsoft.NET\Framework\v2.0.xxxxx where the X's represent your current version of .NET. As an example this could look like this:
http://alexkipman.members.winisp.net/channel9wikiimages/wikiFAQDebugginATask3.jpg
Step 3 - Set Start options command line arguments to point to a dummy project
Based on Step 2 you are running
MSBuild as your debuggible executable. As such you need to give
MSBuild.exe the appropriate command line arguments such as what project are you trying to build. In our case you are trying to build the dummy project we created in step 1 which register and uses the task that you are creating. Assuming your XML project file was called
MyFoobarProject.xml you'd do that by simply typing the following:
http://alexkipman.members.winisp.net/channel9wikiimages/wikiFAQDebugginATask4.jpg
You are now done. Set a breakpoint in your app and F5 away!