Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 638
Alex G. Avatar asked Dec 27 '15 15:12

Alex G.


2 Answers

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
}
like image 108
Christian Specht Avatar answered Sep 20 '22 17:09

Christian Specht


Use copyToOutput inside buildOptions:

{
  "buildOptions": {
    "copyToOutput":  "NLog.config" 
  }
}

or for multiple files declare an array:

{
  "buildOptions": {
    "copyToOutput":  ["NLog.config", "testdata\\"]
  }
}

To copy a directory remember to add the trailing \\.

like image 29
Bjorn Reppen Avatar answered Sep 19 '22 17:09

Bjorn Reppen