ASP.NET Core RC2区域未发布

Vah*_*iri 16 c# asp.net-mvc-areas asp.net-core .net-core-rc2

所以我刚刚更新了我的应用程序以使用ASP.NET Core RC2.我使用Visual Studio发布它并注意到我的区域未发布:

此快照来自src\MyProject\bin\Release\PublishOutput:

在此输入图像描述

这是我Admin在Visual Studio中命名的区域:

在此输入图像描述

我错过了一步还是什么?

Dan*_*rim 21

您需要配置您的publishOptions部分project.json以包含Areas默认模板中未包含的文件夹:

例如:

"publishOptions": {
  "include": [
    "wwwroot",
    "Views",
    "appsettings.json",
    "web.config",
    "Areas"
  ],
  "exclude": [ "bin" ]
}
Run Code Online (Sandbox Code Playgroud)

更新

如果要确保不包含控制器和其他.cs文件,可以使用如下exclude属性进行黑名单publishOptions:

"publishOptions": {
  "include": [ "wwwroot", "Views", "appsettings.json", "web.config", "Areas" ],
  "exclude": [ "**.user", "**.vspscc", "**.cs", "bin" ]
}
Run Code Online (Sandbox Code Playgroud)

如果您更喜欢更严格的安全性,您可以简单地将.cshtml文件列入白名单,而不是包括整个区域文件夹,如下所示:

"publishOptions": {
  "include": [ "wwwroot", "**.cshtml", "appsettings.json", "web.config" ],
  "exclude": [ "bin" ]
}
Run Code Online (Sandbox Code Playgroud)

注意

小心使用通配符,**.cshtml因为它们将包括所有子目录中的所有文件,包括bin目录.如果您在bin先前版本的文件夹中有任何视图,则它们将在新构建输出中再次复制,直到路径变得太长.

  • 为了包含位于Areas文件夹内的所有Views文件夹,请使用 - Areas/**/Views,但由于此处描述的错误,它在RC2和1.0中不起作用 - https://github.com/ dotnet/cli/issues/3286,作为解决方法使用此区域/**/*.cshtml (2认同)