现在我有几个 MVC4 项目。一些 JS 文件为所有这些项目共享,因此我将其放入专用程序集并在更改后将其复制到每个项目。
如何将它作为嵌入式资源放入此程序集并将其提取到我的项目中以与 MVC4 捆绑一起使用? (有没有办法把文件作为一个Bundle对象获取)
最佳答案
How I can put it into this assembly as embedded resource and extract it in my projects to use it with MVC4 bundling?
你不能。捆绑机制不支持嵌入到程序集中的资源。我建议您将这些共享静态资源托管在 CDN(内容交付网络)上,并让您的所有应用程序从这个公共(public) CDN 引用它们。
您可以像这样启用 CDN 支持:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.UseCdn = true; //enable CDN support
//add link to jquery on the CDN
var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",jqueryCdnPath)
.Include("~/Scripts/jquery-{version}.js")
);
...
}
关于asp.net-mvc-4 - 从另一个程序集 ASP、NET MVC 4 获取 js 文件作为嵌入式资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17041751/