MSBuild add file to primary output

2019-06-25 05:53发布

问题:

How can i add some custom file created by MSBuild to project output? i.e. I have blank .csproj, I add Exec task to Target that generates some file.txt and now i want to include this file into "primary output" or "content files".

Thanks, Marek

回答1:

Generally, you just need to include the output files you have and then copy them to the output directory.

<CreateItem Include="$(SourcePath)\file.txt">
  <Output ItemName="FilesToCopy" TaskParameter="Include" />
</CreateItem>

<Copy SourceFiles="@(FilesToCopy)" DestinationFolder="$(OutDir)" />

There's also a variable $(OutputDirectory) for the immediate project. There are many other properties you may find useful also:

https://msdn.microsoft.com/en-us/library/ms164309.aspx https://msdn.microsoft.com/en-us/library/ms164313.aspx