C# 如何使用Bundle转换向Bundle写入包装器?
我想为脚本包编写一个自定义转换,在包中的所有文件周围包装一些JS。我研究了C# 如何使用Bundle转换向Bundle写入包装器?,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我想为脚本包编写一个自定义转换,在包中的所有文件周围包装一些JS。我研究了IBundleTransform接口,我知道我可以向任何包添加如下转换: public class CustomTransformType : IBundleTransform { public void Process(BundleContext context, BundleResponse response) { string bundleResponse = string.Empty
IBundleTransform
接口,我知道我可以向任何包添加如下转换:
public class CustomTransformType : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
string bundleResponse = string.Empty;
foreach (FileInfo file in response.Files)
{
// PROCESS FILE CONTENT
}
response.Content = bundleResponse;
}
}
然而,这让我有责任将所有文件流式传输到一个字符串缓冲区中,然后用自己的代码包装
我想知道是否有办法获取生成的bundle文件并将其用于我的包装器?因此,相反,请执行以下操作:
public class CustomTransformType : IBundleTransform
{
private string wrapBeg = "(function () {";
private string wrapEnd = "})";
public void Process(BundleContext context, BundleResponse response)
{
string bundleResponse = wrapBeg + response.Bundle + wrapEnd;
}
}
上面的代码是我想做的事情的说明,而不是实现
如果上面的内容不可用,有谁能建议一种好的方式来流式处理文件和一些我应该注意的问题吗?您使用的是什么版本的.net?我使用的是4.5版。我的直觉是,在.net core中执行此操作实际上相当简单,因为您可以为它编写一个自定义的gulp函数。以下是4.5中的捆绑文档(如果有帮助)。