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 509299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:59:48+00:00 2026-05-13T06:59:48+00:00

I have a post-build target in MSBuild to copy some build outputs. This is

  • 0

I have a post-build target in MSBuild to copy some build outputs.

This is linked in as a dependency to the AfterBuild target (exposed by Microsoft.CSharp.targets):

<Target Name="AfterBuild" DependsOnTargets="InstallUtil;CopyPostBuildFiles" />

Is there any way to avoid the files being copied if the build didn’t actually re-build?

For example, when the MSBuild dependency analysis asserts that the project doesn’t need to be built because none of its source files have been updated, it doesn’t build, but still executes my copy target. Is there any way to prevent this?

  • 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-13T06:59:48+00:00Added an answer on May 13, 2026 at 6:59 am

    Since you are overriding the AfterBuild target it will always execute after the build occurs. This is the case for a rebuild or a normal build. If you want to perform some actions after the rebuild (and not build) then you should extend the dependency property for the Rebuild target. So in your case to inject the targets after a rebuild occurs your project file should look something like:

    <Project ...>
       <!-- some content here -->
    
       <Import Project="... Microsoft.Csharp.targets" />
    
    
        <PropertyGroup>
            <RebuildDependsOn>
                $(RebuildDependsOn);
                InstallUtil;
                CopyPostBuildFiles
            </RebuildDependsOn>
        </PropertyGroup>
    </Project>
    

    This method extends the property which the Rebuild targets uses to declare what targets it depends on. I’ve detailed this in the article Inside MSBuild, see section Extending the build process.

    Also what you are trying to accomplish may be acheived by the AfterBuild target if you can specify what what files would “trigger” an update to occur. In other words you can specify a set of “inputs” into the target and a set of “outputs” which are both files. If all outputs were created after all inputs then the target would be considerd up to date and skipped. this concept is known as Incremental Building and I’ve coverd it in the article MSBuild Best Practices Part 2. Also I have detailed this in my book, Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build.

    EDIT: Adding BuildDependsOn example

    If you want the target to only execute when the files are actually built and not just when the Rebuild target is executed. Then you should create your project to be like the following:

    <Project ...>
       <!-- some content here -->
    
       <Import Project="... Microsoft.Csharp.targets" />
    
    
        <PropertyGroup>
            <BuildDependsOn>
                $(BuildDependsOn);
                CustomAfterBuild;
            </BuildDependsOn>
        </PropertyGroup>
       <Target Name="CustomAfterBuild" Inputs="$(MSBuildAllProjects);
                @(Compile);                               
                @(_CoreCompileResourceInputs);
                $(ApplicationIcon);
                $(AssemblyOriginatorKeyFile);
                @(ReferencePath);
                @(CompiledLicenseFile);
                @(EmbeddedDocumentation); 
                $(Win32Resource);
                $(Win32Manifest);
                @(CustomAdditionalCompileInputs)"
        Outputs="@(DocFileItem);
                 @(IntermediateAssembly);
                 @(_DebugSymbolsIntermediatePath);                 
                 $(NonExistentFile);
                 @(CustomAdditionalCompileOutputs)">
    
       <!-- Content here -->
    
        </Target>
    
    </Project>
    

    I just copied the inputs and outputs from the CoreCompile target inside of Microsoft.CSharp.targets (I’m assuming your are using C# here) and pasted it here. What this means is that the target will be skipped whenever the CoreCompile target is executed. Also since I extended the BuildDependsOn we know that MSBuild will try and execute it whenever the project is built.

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

Sidebar

Related Questions

I have a post-build event that runs some commands for a c# project. The
I have some post build event to minify my css and javascript using ajaxmin
I have a project which has some post build events that do some copying
I have a relatively simple post-build event happening in VS 2010, just two copy
I have a very similar question to this SO post: TFS Build 2010 -
i have this problem to find a particular xml node l have post this
http://demo.thethemefoundry.com/traction/#post-183 Which wordpress plugin is this, to have post image on the left side
I have a project that has a post-build event that xcopies a DLLs to
I am converting ant to maven2. In build.xml, I have: <target name=clean> <delete file=${dir.dist}/${api.jarfile}
Currently I have a post-build event configured in my web project using Visual Studio

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.