简体   繁体   中英

MSBuild custom task not fired in Visual Studio 2013

In my solution I have a project with this single class:

using System.Windows;
using Microsoft.Build.Utilities;

namespace MetaCode
{
    public class MsBuildTask : AppDomainIsolatedTask
    {
        public override bool Execute()
        {
            System.Threading.Tasks.Task.Run(() => MessageBox.Show("12345678"));
            Log.LogMessage("12345678");
            return true;
        }
    }
}

I added this to another project's csproj file (let's call this project "Genesis" for now):

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="MetaCode.MsBuildTask" AssemblyFile="c:\temp\MetaCode.dll" />
    ...
    <Target Name="AfterBuild">
        <MetaCode.MsBuildTask />
    </Target>
</Project>

But when I hit F5 in Visual Studio 2013 Pro , it builds the projects fine, but nothing happens... No MessageBox showing "12345678" , and no "12345678" text in the "output" panel in Visual Studio. What am I missing here?

(the file "c:\\temp\\MetaCode.dll" exists in that location, and this is the output file of the above "MetaCode" project)

  • First, increase message verbosity:

     Log.LogMessage(MessageImportance.High, "12345678"); 

And add a standard message just to make sure:

<Target Name="AfterBuild">
    <Message Text="About to run MsBuildTask" Importance="high" />
    <MetaCode.MsBuildTask />
</Target>
  • Using task manager, kill all MSBuild.exe processes to clear all previous versions of your custom task.

  • Rebuild the MSBuild task.

  • Rebuild the consumer project and watch the output pane.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM