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

自闭症网瘾萝莉.ら 提交于 2019-12-04 00:38:35

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
}

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 \\.

By default all code files in a directory containing a project.json are included in the project. You can control this with the include/exclude sections of the project.json.

More info: http://docs.asp.net/en/latest/dnx/projects.html#including-excluding-files

You use the content section of project.json like this

{
  "content": [
    "NLog.config"
  ]
}

Now the documentation says that the file should have been copied by default as the content default if * (wildcard for all files), but you can force it with the explicit stating of the file you want in the content section.

Stajs

I think it is broken in RC1. I was also looking how to get content files copied to the output folder, and found this issue that looks similar to what we are seeing.

As @Nkosi points out, the default for content is **/* (you can see via the docs link he provided, and also by the schema).

As for your postbuild step, you can get it going by "producing outputs".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!