VS Code: How to copy files to output directory depending on build configurations
10,141
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x86' Or '$(RuntimeIdentifier)' == 'win-x64'">
<None Update="foo.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<None Update="foo.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Steps:
- Create a console app by running
dotnet new console
- Add foo.txt and foo.xml to the project folder.
- Edit the
.csproj
file as above. - Build the project with multiple configurations.
dotnet build -c Release -r win-x86
foo.xml
is copied only for ax-64
build whereasfoo.txt
is copied for both RID's

Author by
Mathew O'Dwyer
I get a little to excited about game engine development. C#, Java, I cry when I have to read example code in C/C++.
Updated on July 22, 2022Comments
-
Mathew O'Dwyer 4 months
I just started a new project in VS Code (C#, .NET Core). Anyways, I want to be able to copy files from within my project directory to the output directory like I can in visual studio. But I also want to copy specific files depending on whether or not I'm building for 32 or 64 bit.
I've looked around but so far all I've learnt how to do is copy files regardless of my build configurations.