Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files from being published in ASP.NET Core?

I have noticed that when I publish the new ASP.NET project, then it puts all the non-code files in the root folder in packages. E.g. these files end up there:

  • Publish profiles
  • gulpfile.js

There is no real need to include those in the published folder. In older solutions it was just as easy as modifying properties of the files to exclude them. Now properties do something completely different and open a quite useless dialog where you can only see the path of the file. Perhaps it's possible to do some other way? Ideally the IDE should be smart enough not to publish these common files, but for some custom it should be a way to exclude them.

It's of course not so big of a problem that some additional files get published, but it makes sense to exclude them as well.

P.S. The possible proposed duplicate is not the same, since it deals only with the old project/solution structure, while ASP.NET Core introduced a new one where the other solution is not applicable.

like image 553
Ilya Chernomordik Avatar asked Dec 18 '15 09:12

Ilya Chernomordik


1 Answers

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.

The most common sections that you will see for including and excluding files are:

{
  "compile": "*.cs",
  "exclude": [
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "**.xproj",
    "**.user",
    "**.vspscc"
  ]
}
  • The compile section specifies that only .cs files will be compiled.
  • The exclude section excludes any files in the node_modules and bower_components directories. Even if sections have .cs extensions.
  • The publishExclude section allows you to exclude files from the publish output of your project. In this example, all .xproj, .user, and .vspscc files from the output of the publish command.

From here

like image 117
Stas Boyarincev Avatar answered Sep 29 '22 03:09

Stas Boyarincev