Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: How to copy files to output directory depending on build configurations

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.

like image 558
Mathew O'Dwyer Avatar asked Apr 29 '18 05:04

Mathew O'Dwyer


1 Answers

<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:

  1. Create a console app by running dotnet new console
  2. Add foo.txt and foo.xml to the project folder.
  3. Edit the .csproj file as above.
  4. Build the project with multiple configurations. dotnet build -c Release -r win-x86
  5. foo.xml is copied only for a x-64 build whereas foo.txt is copied for both RID's

Output folder

like image 164
GuruCharan94 Avatar answered Sep 24 '22 14:09

GuruCharan94