15

So I just updated my app to use ASP.NET Core RC2. I published it using Visual Studio and noticed that my Area is not published:

This snapshot is from src\MyProject\bin\Release\PublishOutput:

enter image description here

And here is my Area, named Admin in Visual Studio:

enter image description here

Am I missing an step or what?

Vahid Amiri
  • 10,769
  • 13
  • 68
  • 113

2 Answers2

21

You need to configure your publishOptions section of project.json to include the Areas folder which is not included in the default template:

ex:

"publishOptions": {
  "include": [
    "wwwroot",
    "Views",
    "appsettings.json",
    "web.config",
    "Areas"
  ],
  "exclude": [ "bin" ]
}

Update

If you want to ensure that your controllers and other .cs files are not included, you can blacklist with the exclude property of publishOptions like so:

"publishOptions": {
  "include": [ "wwwroot", "Views", "appsettings.json", "web.config", "Areas" ],
  "exclude": [ "**.user", "**.vspscc", "**.cs", "bin" ]
}

If you prefer more restrictive security, you can simply whitelist .cshtml files instead of including the entire Areas folder like so:

"publishOptions": {
  "include": [ "wwwroot", "**.cshtml", "appsettings.json", "web.config" ],
  "exclude": [ "bin" ]
}

Note

Be careful using wildcards like **.cshtml as they will include all files in all subdirectories, including the bin directory. If you have any views in your bin folder from a previous build, they will be duplicated again inside the new build output until the path becomes too long.

Daniel Grim
  • 2,261
  • 19
  • 22
  • This indeed publishes the `Areas` folder BUT it also publishes the `Controllers` folder inside an area with `.cs` files! That's not wanted! – Vahid Amiri May 19 '16 at 14:36
  • Updated my answer to include details of white-listing only cshtml files, rather than including the entire Areas folder – Daniel Grim May 19 '16 at 14:49
  • 2
    In order to include all Views folders which are located inside Areas folder, use this - Areas/**/Views, but it doesn't work in RC2 and 1.0 because of bug which is described here - https://github.com/dotnet/cli/issues/3286, as workaround use this Areas/**/*.cshtml – Sergey Jun 29 '16 at 04:17
0

Adding Areas will copy everything including the .cs files.

so should add "Areas/**/Views/**/*.cshtml" and "Areas/ * /.cshtml" under publish options instead of only "Areas"

Nouman Bhatti
  • 1,341
  • 6
  • 28
  • 54