Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6990469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:21:17+00:00 2026-05-27T19:21:17+00:00

I am learning how to use MSBuild recently so I decided to tackle writing

  • 0

I am learning how to use MSBuild recently so I decided to tackle writing my own custom MSBuild task. What I found is that MSBuild is calling my task just fine… but it calls it over and over and over again. It repeats the call to it many times, even though the msbuild project calls it only once.

Here is my project XML:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
        xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >

<PropertyGroup>
<BuildDir>build directory specified here</BuildDir>
.. various other stuff here too
</PropertyGroup>
<Import Project="file1.xml" />
<Import Project="file2.xml" />

<UsingTask TaskName="CopyToBuild.Copy_To_Build"
           AssemblyFile="CopyToBuild.dll" />

<Target Name="MyNewCopyTask">
    <Copy_To_Build  SourceFiles="@(copy_to_build)"
            DestinationFolder="%(Destination)"
            SkipUnchangedFiles="true"
            BuildDirectory="$(BuildDir)" />
</Target>

</Project>

So as you can see I call my Copy_To_Build task only once in the project. I import an xml file that contains items that is passed in to the SourceFiles attribute of my Copy_To_Build task. Everything works great. Except for one thing: the problem is that my Execute method on my custom task gets called more than once.

public class Copy_To_Build : Microsoft.Build.Utilities.Task
{
    [Required]
    public ITaskItem[] SourceFiles { get; set; }

    [Required]
    public ITaskItem[] DestinationFolder { get; set; }

    public String BuildDirectory { get; set; }

    public bool Clean { get; set; }

    public bool SkipUnchangedFiles { get; set; }

    public override bool Execute()
    {
        Console.WriteLine("Build Directory: {0}", BuildDirectory);
        ...
    }
}

I know it’s getting called more than once because I put a print statement in there which reveals that the function is getting more than once. I expected it to get called only once.

Is it getting called more than once because I have some sort of threading option set? I put in a statement to print the current thread:

Console.WriteLine("Current Thread: {0}", System.Threading.Thread.CurrentThread.ManagedThreadId);

But that revealed that everything was on the same thread.
Last but not least, here is the command line script I am using to call everything:

@echo off

call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" x64

rem set some build properties
set MISC=/nologo /verbosity:Normal
set LOGGING=/fileLogger /fileloggerparameters:LogFile=msbuild_foo.log;Encoding=UTF-8;Verbosity=Normal
set PROPERTY=/property:Platform=x64;Configuration=DebugUnicode;BuildDir=E:\foo
set TARGET=/target:MyNewCopyTask

msbuild %MISC% %LOGGING% %PROPERTY% %TARGET% foo.xml

pause

@echo on

So in summary: Why is my task getting called more than once?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:21:18+00:00Added an answer on May 27, 2026 at 7:21 pm
      <Copy_To_Build  SourceFiles="@(copy_to_build)"
            DestinationFolder="%(Destination)"
            SkipUnchangedFiles="true"
            BuildDirectory="$(BuildDir)" />
    

    It will be called once per unique value of the “Destination” metadata. This is called ‘batching’. You could either do it like the way it is working right now, or make DestinationFolder property optional, and in case it is not specified, then the task can look for the “Destination” metadata in the items “SourceFiles” and copy the item to that folder.

    But the usual way to do it as you have right now, just make DestinationFolder a string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning to use SCons, anticipating that it solves some of my
I'm interested in learning to use OpenGL and I had the idea of writing
I'm just learning about MSBuild and I'm wondering what are some useful tasks people
I'm just learning to use RVM, and would like to know how I can
I am just learning to use the Entity framework and I wondered how I
I'm learning to use SIMD capabilities by re-writing my personal image processing library using
im learning to use openGL and iv been told that because my wheel arches
I'm just learning to use XCode and program in Objective-C (my plan is to
I'm learning to use google task api rest. i have succeed getting access tokken.
Just started learning to use the grid so please excuse me for the possibly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.