2

How can I include file as resource output from Visual Studio Code? I want nlog.config to be copied to the output directory.

This is ASP.NET Core Web API project.

In VS 2017 this would be: "Build Action: Content" option in the properties menu.

user007
  • 1,122
  • 1
  • 10
  • 30
  • 1
    `` is fine for this, yeah. Unfortunately, you don’t get tooling in Visual Studio Code for this, so you have to know how to modify your project file for this. – poke Apr 29 '18 at 19:12
  • maybe it's a good idea to add your answer, as answer to stackoverflow :) (and accept it) – Julian May 02 '18 at 22:40

2 Answers2

2

I had to manually edit project and add nlog settings.

In VS 2017 this can be done through the UI: - "Build Action: Content" option in the properties menu of the nlog.config.

Final version of the project in VS Code:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <EnableDefaultContentItems>false</EnableDefaultContentItems> //added
  </PropertyGroup>

  //commented
  <!-- <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup> -->

  //added
  <ItemGroup>
    <Content Include="nlog.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
user007
  • 1,122
  • 1
  • 10
  • 30
0

Sometimes, you may need the defaultContentItems to handle the default loading. And another way to copy the config file is this: https://stackoverflow.com/a/44378406/15237039

Wei Yan
  • 21
  • 2