ashes999
ashes999

Reputation: 10163

Copying Content files on build with Visual Studio Code

I'm working on a C# project that has Content files. In MonoDevelop, I can set the type to Content and the Build Action to Copy if Newer. I can do something similar in Visual Studio.

How do I do this with Visual Studio Code? I'm not opening a solution file (I'm opening a directory), and I don't see anything in tasks.json or in VSCode that I can use to configure this.

Upvotes: 12

Views: 11673

Answers (3)

Automation Curry Puff
Automation Curry Puff

Reputation: 372

Updating the .csproj file with the below line of code helped me

<ItemGroup>
   <Content Include="FolderPath/*">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
   </Content>
</ItemGroup> 

Upvotes: 11

Ricardo Maroquio
Ricardo Maroquio

Reputation: 595

This is a direct code if you want to include an appsettings.json in the output directory. This is working on Visual Studio Code (updated version up to the publishing date of this post).

<ItemGroup>
    <None Include="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
</ItemGroup>

Upvotes: 2

LukaszTaraszka
LukaszTaraszka

Reputation: 859

Try to manipulate csproj:

  <ItemGroup>
      <None Update="FILE_PATH">
          <CopyToOutputDirectory>ACTION_TYPE</CopyToOutputDirectory>
      </None>
  </ItemGroup>
  • FILE_PATH is relative path inside your project, ex. "nlog.config".
  • ACTION_TYPE - there are two possible choices: PreserveNewest (copy if never) and Always

Upvotes: 13

Related Questions