我们有多个相互链接的 .NET MVC 项目,但一些脚本和 css 文件对于所有项目都是相同的。 文件夹结构如下
- Root folder
- Assets
- Js
- CSS
- Project 1
- Project 2
- Project 3
所有常见的 js 都位于 Assets/js 和 Assers/Css 文件夹内,该文件夹位于项目文件夹之外。 我们可以将 Assets 文件夹捆绑到项目 1,2 和 3 中吗?
感谢您提前提供的任何提示/指导。
最佳答案
是的,你可以。您只需要在每个项目的 App_Start\BundleConfig.cs
文件中添加一些代码即可。
像这样,您在方法RegisterBundles
中添加:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("Root/Assets/js").Include(
"Root/Assets/Js/*.js")); //You put your path where there is the Root
bundles.Add(new StyleBundle("Root/Assets/css").Include(
"Root/Assets/CSS/*.css")); //You put your path where there is the Root
// Code removed for clarity.
}
然后你可以将这些行放入每个 Layout.cshtml
@Styles.Render("Root/Assets/css")
@Scripts.Render("Root/Assets/js")
调用您的 Js
库和 CSS
文件。
希望对你有帮助
关于c# - 如何捆绑项目文件夹外部的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23241422/