积极答复者
求助,调用Task的实现类,报错,求解决

问题
-
这个例子就能重现我报的错:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Build.Utilities; namespace ConsoleApplication2 { class Program:Task { static void Main(string[] args) { Program p = new Program(); p.Execute(); } public override bool Execute() { Log.LogMessage("Hello World!"); return true; } } }
异常信息:任务尚未初始化就试图进行日志记录。消息为: Hello World!
未处理InvalidOperationException
答案
-
这个是要在 MSBuild 里面用的吧,怎么会直接写成了 Console Application?您把它换成 DLL 类型试试看,然后利用 MSBuild 脚本 (*.proj, *.target) 利用 XML 使用这个 Task。比如:
<Project ...>
<Task Name="MyTask">
<MyTask MyProperty="MyValue" ... />
</Task>
</Project>
Mark Zhou -
您好,威猛狂奔:
欢迎您来到MSDN论坛。
正如mazhou所说的,这个应该在MSBuilt里面使用的,您也可以参见下面的方式来使用Log.LogMessage():
http://msdn.microsoft.com/en-us/library/microsoft.build.utilities.task.aspx
如果您还有任何相关问题,请随时告诉我们。
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the C# Forum! If you have any feedback, please tell us.- 已标记为答案 Neddy Ren 2011年1月19日 1:15
全部回复
-
这个是要在 MSBuild 里面用的吧,怎么会直接写成了 Console Application?您把它换成 DLL 类型试试看,然后利用 MSBuild 脚本 (*.proj, *.target) 利用 XML 使用这个 Task。比如:
<Project ...>
<Task Name="MyTask">
<MyTask MyProperty="MyValue" ... />
</Task>
</Project>
Mark Zhou -
您好,威猛狂奔:
欢迎您来到MSDN论坛。
正如mazhou所说的,这个应该在MSBuilt里面使用的,您也可以参见下面的方式来使用Log.LogMessage():
http://msdn.microsoft.com/en-us/library/microsoft.build.utilities.task.aspx
如果您还有任何相关问题,请随时告诉我们。
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the C# Forum! If you have any feedback, please tell us.- 已标记为答案 Neddy Ren 2011年1月19日 1:15