Copy content files to output directory of DNX Console app via project.json

Alex G. picture Alex G. · Dec 27, 2015 · Viewed 7.5k times · Source

I've just started working with DNX 1.0.0-rc1-update1 in VS2015. My first app is a 'Console Application (package)' project. Everything works, except NLog logging. I suspect it's because the NLog.config doesn't get copied to the output folder. How can I tell VS to copy this file to the output folder via project.json?

I've tried adding a 'resource' variable like this but it doesn't work:

project.json

...
"resource":"NLog.config",
...

EDIT 1: I'm using dnx451 so compatibility is not an issue.

EDIT 2: I added the following to project.json

"scripts": {
    "postbuild": [
      "%project:Directory%/../scripts/copy_resources.bat \\\"%project:Directory%\\\" \\\"%project:Directory%/../artifacts/bin/%project:Name%/%project:Version%/dnx451\\\""
    ] 
  }

copy_resources.bat

echo "Running script" >> C:\logs\log.txt
echo %1 >> C:\logs\log.txt
echo %2 >> C:\logs\log.txt

xcopy %1\NLog.config %2 /U /Y

There's nothing in the output window in VS to indicate that the script was actually run. Furthermore, log.txt is empty.

How can I debug the build process?

Answer

Christian Specht picture Christian Specht · Aug 3, 2016

In the meantime, .NET Core RTM was published.

Now, the current way to get stuff copied to the output folder is using the buildOptions section in project.json.

There's the copyToOutput option which you can use like this:

Before:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  // more stuff
}

After:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true,
    "copyToOutput": { "includeFiles": [ "NLog.config" ] }
  },

  // more stuff
}