MSBuild custom task “Hello World” walkthrough

眉间皱痕 提交于 2019-12-22 04:01:41

问题


Can someone write (or link to) a walkthrough that explains exactly how to create a custom MSBuild task and run it during a build? I'm looking for a custom task that inherits from Microsoft.Build.Utilities.Task and does only this:

public override bool Execute()
{
    Log.LogMessage("Hello world!");
    return true;
}

(I've been working on this for hours and keep getting the "The [whatever] task was not found. Check the following" message. I think I must be missing an essential step somewhere. If there's a clear tutorial I can follow, perhaps I'll figure out where I'm falling short.)


回答1:


Are you declaring your custom task in your MSBuild project file? You need a line like this:

    <UsingTask AssemblyFile="C:\PathTo\MyTasks.dll" TaskName="MyTasks.HelloWord" />

Then MSBuild can execute your task.




回答2:


See

  1. Best Practices For Creating Reliable Builds section Creating Custom Tasks.
  2. THE CUSTOM MSBUILD TASK COOKBOOK from Bart De Smet


来源:https://stackoverflow.com/questions/5170475/msbuild-custom-task-hello-world-walkthrough

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!