MVC 6中多个网站的通用wwwroot文件夹 [英] Common wwwroot folder for multiple websites in MVC 6

查看:206
本文介绍了MVC 6中多个网站的通用wwwroot文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个网站使用/wwwroot/assets文件夹(html主题,css和javascript文件)加载静态内容.

当前,我正在每个站点中复制assets文件夹.我所有的项目都位于一个公共的父目录下.

我不想将/wwwroot/assets文件夹复制到每个网站中.有没有一种方法可以在所有站点之间共享一个assets文件夹.可能是通过提供直接文件系统路径或其他方式?

解决方案

目前尚不清楚将项目捆绑在一起以进行部署的kpm代码,它似乎将项目目录与wwwroot键中存储的内容结合在一起,因此即使Visual Studio可能不理解它,也似乎支持相对路径.在命令行中使用kpm bundle可以确认这一点,并且在使用相对路径时,src上方的目录会正确捆绑.

取决于您的特定需求,有一种方法可以使kpm Visual Studio感到满意,但是这取决于您的构建环境,确定这是否适合您.

Windows,OSX和Linux都支持为目录创建符号链接,这将使您可以将资产目录放在文件系统中的一个位置,然后在其他位置创建指向该目录的链接.例如,如果您在/projects/shared/assets中有资产,则可以在两个其他项目(例如/projects/project1/src/wwwroot/assets)中创建一个指向真实"位置的链接.

在Windows中,该命令可能是这样的

mklink /j "C:\link\to\create" "C:\path\to\assets"

所以,如果您这样做

mklink /j "C:\source\shared\assets" "C:\source\project1\src\wwwroot\assets"

project1似乎在wwwroot内部具有一个资产目录,并且构建过程很高兴,因为在每个项目中似乎文件都是本地的.这里要注意的一件事是Windows支持多种不同类型的链接. /j专门创建一个 junction ,而不是一个真正的符号链接.差异有些细微,但这是对差异的很好的描述.足以知道,如果您在本地工作,/j命令不需要管理权限,Visual Studio和kpm都会很高兴.

在OSX和Linux中,命令类似:

ln -s /link/to/create /path/to/assets

和Windows一样,它们支持不同类型的链接.

在任何情况下,在适当的情况下,这都可能会很好用,而无需新的ASP.NET项目结构的任何特殊支持,但最终也很高兴.

I have multiple websites which use /wwwroot/assets folder (html theme, css and javascript files) to load the static content.

Currently I am copying assets folder in each site. All of my projects are sitting under a common parent directory.

I don't want to copy the /wwwroot/assets folder into each website. Is there a way to share one assets folder between all sites. May be by providing a direct file system path or something?

解决方案

At the moment it's not clear from the documentation what sorts of values the webroot key in the project.json file will accept, but so far it would appear that Visual Studio doesn't care for very complicated paths. For example, setting the value to ../wwwroot causes the entry to disappear in the Solution Explorer.

If you look at the kpm code that bundles your project up for deployment, it appears to combine your project's directory with whatever is stored in the wwwroot key, so even though Visual Studio may not understand it, relative paths appear to be supported. Using kpm bundle from the command line confirms this, and a directory above src bundles correctly when using a relative path.

Depending on your particular needs, there is one way that should work that makes kpm and Visual Studio happy, but it will depend on your build environment as to whether that is a good option for you.

Windows, OSX, and Linux all support creating symbolic links for directories, which would allow you to have your assets directory in one location in the filesystem and then create links to it elsewhere. For example, if you had assets in /projects/shared/assets, you could create a link in both of your other projects (e.g. /projects/project1/src/wwwroot/assets) that point to the "real" location.

In Windows, the command would might something like this

mklink /j "C:\link\to\create" "C:\path\to\assets"

So if you did

mklink /j "C:\source\shared\assets" "C:\source\project1\src\wwwroot\assets"

project1 would appear to have an assets directory inside of wwwroot and the build process would be happy since it would appear to each project that the files were local. One thing to note here is that Windows supports a number of different sorts of links. /j specifically creates a junction rather than a true symbolic link. The differences are a bit subtle, but this is a good description of the differences. It is enough to know that if you're working locally, the /j command doesn't require administrative rights and Visual Studio and kpm will both be happy.

In OSX and Linux, the command is similar:

ln -s /link/to/create /path/to/assets

and like Windows, they support different sorts of links.

In any case, under the right circumstances, this might work well without needing any special support from the new ASP.NET project structure, but it would be nice to eventually have that as well.

这篇关于MVC 6中多个网站的通用wwwroot文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆