如何在ASP.NET Core中为wwwroot配置替代文件夹? [英] How to Configure an Alternative Folder to wwwroot in ASP.NET Core?
问题描述
是否可以在ASP.NET Core中配置其他文件夹来替换wwwroot?如果是的话,此更改如何产生副作用?
Is it possible to configure a different folder to replace wwwroot in ASP.NET Core? And if yes, how and are there any side effects to this change?
在整个项目中当前唯一包含 wwwroot
的配置可以在 project.json
中找到,如以下代码所示;但是用新文件夹的名称替换值不足以读取静态文件(例如: index.html
).
The only config that currently includes wwwroot
in the entire project is found in project.json
as seen in the code below; but replacing the value with the name of the new folder is not enough for the static file (ex: index.html
) to be read.
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
推荐答案
是否可以在ASP.NET Core中配置其他文件夹来替换wwwroot?
Is it possible to configure a different folder to replace wwwroot in ASP.NET Core?
是的.在您的 Program
类中添加一个 UseWebRoot
调用:
Yes. Add a UseWebRoot
call in your Program
class:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseWebRoot("myroot") // name it whatever you want
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
此更改有副作用吗?
are there any side effects to this change?
我能想到的有三个:
- Bower软件包管理器无法正常运行,因为它会在
wwwroot
中寻找lib
文件夹.我不确定这是否可以配置. - 您需要修复
bundleconfig.json
才能查看新目录. - 您将需要更新
project.json
中的include
部分,以将新目录包括在发布输出中.
- The Bower package manager will not work properly, as it looks for a
lib
folder inwwwroot
. I'm not certain if this is configurable. - You will need to fix
bundleconfig.json
to look at the new directory. - You will need to update the
include
portion inproject.json
to include your new directory in the publish output.
这篇关于如何在ASP.NET Core中为wwwroot配置替代文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!