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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:36:14+00:00 2026-06-18T08:36:14+00:00

I have a custom msbuild task that is generating some output files to the

  • 0

I have a custom msbuild task that is generating some output files to the output directory ($(TargetDir)) of a ProjectA. Current code is something like this:

<MyCustomTask ...>
   <Output TaskParameter="OutputFiles" ItemName="FileWrites"/>
</MyCustomTask>

A ProjectB is referencing ProjectA but the problem is that when building ProjectB, generated files by MyCustomTask are not copied to the output directory of the ProjectB.

How can we get dynamically generated additional files to be copied as part of project dependency with MSBuild?

  • 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-06-18T08:36:15+00:00Added an answer on June 18, 2026 at 8:36 am

    I have finally managed to perform automatically the copy from Project B without having to modify it. IIya was not so far from the solution, but the fact is that I cannot generate statically as the list of files to generate from Project A with MyCustomTask is dynamic. After digging more into Microsoft.Common.targets, I have found that ProjectB will get the list of output from Project A by calling the target GetCopyToOutputDirectoryItems. This target is dependent from AssignTargetPaths which itself is dependent on the target list property AssignTargetPathsDependsOn.

    So in order to generate dynamically content and to get this content being copied automatically through standard project dependency, we need to hook Project A at two different places:

    • In AssignTargetPathsDependsOn as it is called indirectly by Project B on Project A through GetCopyToOutputDirectoryItems. And also it is indirectly called by Project A when PrepareResource is called. Here, we are just outputing the list of files that will be generated (by Project A) or consumed by Project B. AssignTargetPathsDependsOn will call a custom task MyCustomTaskList which is only responsible to output the list of files (but not to generate them), this list of files will create dynamic “Content” with CopyOutputDirectory.
    • In BuildDependsOn in order to actually generate the content in Project A. This will call MyCustomTask that will generate the content.

    All of this was setup like this in ProjectA:

    <!-- In Project A -->
    
    <!-- Task to generate the files -->
    <UsingTask TaskName="MyCustomTask" AssemblyFile="$(PathToMyCustomTaskAssembly)"/>
    
    <!-- Task to output the list of generated of files - It doesn't generate the file -->
    <UsingTask TaskName="MyCustomTaskList" AssemblyFile="$(PathToMyCustomTaskAssembly)"/>
    
    <!-- 1st PART : When Project A is built, It will generate effectively the files -->
    <PropertyGroup>
      <BuildDependsOn>
        MyCustomTaskTarget;
        $(BuildDependsOn);
      </BuildDependsOn>
    </PropertyGroup>
    
    <Target Name="MyCustomTaskTarget">
      <!-- Call MyCustomTask generate the files files that will be generated by MyCustomTask -->
      <MyCustomTask
          ProjectDirectory="$(ProjectDir)"
          IntermediateDirectory="$(IntermediateOutputPath)"
          Files="@(MyCustomFiles)"
          RootNamespace="$(RootNamespace)"
          >
      </MyCustomTask>
    </Target>
    
    <!-- 2nd PART : When Project B is built, It will call GetCopyToOutputDirectoryItems on ProjectA so we need to generate this list when it is called  -->
    <!-- For this we need to override AssignTargetPathsDependsOn in order to generate the list of files -->
    <!-- as GetCopyToOutputDirectoryItems  ultimately depends on AssignTargetPathsDependsOn -->
    <!-- Content need to be generated before AssignTargets, because AssignTargets will prepare all files to be copied later by GetCopyToOutputDirectoryItems -->
    <!-- This part is also called from ProjectA when target 'PrepareResources' is called -->
    <PropertyGroup>
      <AssignTargetPathsDependsOn>
        $(AssignTargetPathsDependsOn);
        MyCustomTaskListTarget;
      </AssignTargetPathsDependsOn>
    </PropertyGroup>
    
    <Target Name="MyCustomTaskListTarget">
    
      <!-- Call MyCustomTaskList generating the list of files that will be generated by MyCustomTask -->
      <MyCustomTaskList
          ProjectDirectory="$(ProjectDir)"
          IntermediateDirectory="$(IntermediateOutputPath)"
          Files="@(MyCustomFiles)"
          RootNamespace="$(RootNamespace)"
          >
          <Output TaskParameter="ContentFiles" ItemName="MyCustomContent"/>
      </MyCustomTaskList>
    
      <ItemGroup>
        <!--Generate the lsit of content generated by MyCustomTask -->
        <Content Include="@(MyCustomContent)" KeepMetadata="Link;CopyToOutputDirectory"/>
      </ItemGroup>
    </Target>
    

    This method is working with anykind of C# projects that is using Common.Targets (so It is working with pure Desktop, WinRT XAML App or Windows Phone 8 projects).

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

Sidebar

Related Questions

We have written a custom msbuild task that does some pre-processing of code files
I have a custom MSBuild task that peeks inside an assembly to get some
I have a custom MsBuild task that sends an email (does some special stuff
I have a custom MSBuild task, which processes a set of files and returns
I have a custom msbuild task with an output parameter defined below public class
I have a very odd issue, where I've created a custom MSBuild task that
I want to create a custom MSBuild task that changes my .cs files before
I have written a custom MSBuild task, call it TaskA, that parses a file
I have a custom MSBuild task for xUnit.net. When the task is running, if
I've written a custom MSBuild task to generate model code from MSSQL stored procedures.

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.