gpt4 book ai didi

c# - 有没有办法以编程方式导出/保存生成的 javascript 和 css 包?

转载 作者:行者123 更新时间:2023-11-29 21:58:03 24 4
gpt4 key购买 nike

我正在使用 System.Web.Optimization BundleTable 进行 CSS 和 JavaScript 文件捆绑。我可以通过转到Chrome Developer ToolsSources 选项卡然后单击 bundle I would like save 然后在 code 上单击鼠标右键和 另存为(如下截图)

enter image description here

我想知道有没有办法以编程方式保存它们(javascript 或 .NET 我不介意以太),因为我需要通过将它们与旧版本进行比较来测试捆绑文件中的更改以查看他们是否改变了。最终产品最有可能是 Selenium 测试。

最佳答案

我自己整理的。

    public static string GetBundleContents(string virtualPath)
{
OptimizationSettings config = new OptimizationSettings()
{
ApplicationPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,
BundleTable = BundleTable.Bundles
};

BundleResponse response = Optimizer.BuildBundle(virtualPath, config);
return response.Content;
}

public static void WriteBundlesToDisk(string path)
{
foreach (var bundle in BundleTable.Bundles)
{
var bundleContents = BundleConfig.GetBundleContents(bundle.Path);
File.WriteAllText(string.Format("{0}/{1}.{2}", path, bundle.Path.Split('/').Last(), BundleConfig.GetFileExtensionByBundleType(bundle)), bundleContents);
}
}

public static string GetFileExtensionByBundleType(Bundle bundle)
{
if (bundle is ScriptBundle)
return "js";
else if (bundle is StyleBundle)
return "css";
return "folderBundle";
}

用法:

BundleConfig.WriteBundlesToDisk("c://bundles");

旁注:上面的解决方案没有正确处理一种名为 System.Web.Optimization.DynamicFolderBundle 的包,它将保存为 .folderBundle文件类型。

关于c# - 有没有办法以编程方式导出/保存生成的 javascript 和 css 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25389114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com