There's quite a few ways to achieve your goals, depending on what your needs are.
The easiest approach is setting the metadata (`CopyToOutputDirectory` / `CopyToPublishDirectory`) items conditionally (assuming `.txt` being a `None` item instead of `Content`, if it doesn't work, try `<Content>` instead):
<!-- language: lang-xml -->
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<None Update="foo.txt" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
If more control is required, the most versatile approach is to add custom targets that hook into the build process in the csproj file:
<!-- language: lang-xml -->
<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="foo.txt" DestinationFolder="$(OutDir)" />
</Target>
<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
<Copy SourceFiles="foo.txt" DestinationFolder="$(PublishDir)" />
</Target>
This copies a file to the respective directories. For more options for the `<Copy>` task, see [its documentation][1]. To limit this to certain configurations, you can use a `Condition` attribute:
<!-- language: lang-xml -->
<Target … Condition=" '$(Configuration)' == 'Release' ">
This `Condition` attribute can be applied both on the `<Target>` element or on task elements like `<Copy>`.
[1]:
[To see links please register here]