からCSSファイルを除外しますが、私はそれから1つのcssファイルを除外したいです。 各CSSファイルをバンドルに指定せずにこれを行うことは可能ですか?asp.net MVCは、私は、このようなバンドル <pre><code>bundles.Add(new StyleBundle("~/Content/themes/default/css") .IncludeDirectory("~/Content/themes/Default", "*.css")); </code></pre> <p></p>を持つバンドル
答えて
IgnoreList.Ignoreを試してください。 bundles.IgnoreList.Ignore(...)
。
:https://stack247.wordpress.com/2014/04/18/asp-net-mvc-4-bundles-ignore-list/ – Kildareflare
これは悪い答えです。 Ignoreの使用方法やアクセス方法については説明していません。それはここでの特質のどれも説明しない小さなスニペットでいくつかの貧弱なドキュメンテーションへの単なるリンクです。ワードプレスサイトについてのコメントは、ここで最も有用なものです。 – Liam
拡張メソッドは、ここで必要なものが考えられます。
public static class BundleExtentions
{
public static Bundle IncludeDirectoryWithExclusion(this StyleBundle bundle, string directoryVirtualPath, string searchPattern, params string[] toExclude)
{
var folderPath = HttpContext.Current.Server.MapPath(directoryVirtualPath);
foreach (var file in Directory.GetFiles(folderPath, searchPattern))
{
if (!String.IsNullOrEmpty(Array.Find(toExclude, s => s.ToLower() == file.ToLower())))
{
continue;
}
bundle.IncludeFile(directoryVirtualPath + "/" + file);
}
return bundle;
}
そして使い方は次のようになります。
bundles.Add(new StyleBundle("~/Content/themes/default/css")
.IncludeDirectoryWithExclusion("~/Content/themes/Default", "*.css", "file-you-dont-want.css"));
以上が未いるので、私は、現時点ではPCではありませんよあなたのソリューションのテンプレートを提供する必要があります。
私は検索パターンを追加し、短所を.minバージョンに修正するためにこの答えを拡張しました:http://stackoverflow.com/a/36080620/1671558 –
既存のIncludeDirectory
メソッドをオーバーロードし、サブディレクトリの検索をサポートする別の拡張メソッドがあります。それは.min「とのバンドルのデフォルトの動作を壊し
1):
public static class BundleExtensions
{
public static Bundle IncludeDirectory(
this Bundle bundle,
string directoryVirtualPath,
string searchPattern,
params string[] filesToExclude)
{
return IncludeDirectory(bundle, directoryVirtualPath, searchPattern, false, filesToExclude);
}
public static Bundle IncludeDirectory(
this Bundle bundle,
string directoryVirtualPath,
string searchPattern,
bool searchSubdirectories,
params string[] filesToExclude)
{
var physicalPath = HttpContext.Current.Server.MapPath(directoryVirtualPath);
return bundle.Include(Directory
.EnumerateFiles(physicalPath, searchPattern, searchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Select(physicalFileName => physicalFileName.Replace(physicalPath, directoryVirtualPath).Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
.Where(virtualFileName => !filesToExclude.Contains(virtualFileName))
.ToArray());
}
}
私はそれが持っていたことを、いくつかの欠点を修正するためにジョン・マルコム(およびSatpal hereによっていくつかのアップデート)により良い提案を改善しています"ファイル
2)それは、検索パターンを許可していませんが、
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Optimization;
public static class BundleExtentions
{
public static Bundle IncludeDirectoryWithExclusion(this Bundle bundle, string directoryVirtualPath, string searchPattern, bool includeSubDirectories, params string[] excludePatterns)
{
string folderPath = HttpContext.Current.Server.MapPath(directoryVirtualPath);
SearchOption searchOption = includeSubDirectories
? SearchOption.AllDirectories
: SearchOption.TopDirectoryOnly;
HashSet<string> excludedFiles = GetFilesToExclude(folderPath, searchOption, excludePatterns);
IEnumerable<string> resultFiles = Directory.GetFiles(folderPath, searchPattern, searchOption)
.Where(file => !excludedFiles.Contains(file) && !file.Contains(".min."));
foreach (string resultFile in resultFiles)
{
bundle.Include(directoryVirtualPath + resultFile.Replace(folderPath, "")
.Replace("\\", "/"));
}
return bundle;
}
private static HashSet<string> GetFilesToExclude(string path, SearchOption searchOptions, params string[] excludePatterns)
{
var result = new HashSet<string>();
foreach (string pattern in excludePatterns)
{
result.UnionWith(Directory.GetFiles(path, pattern, searchOptions));
}
return result;
}
}
を除外するためのファイルだけ私が持っている使用例は、角から始まるlibフォルダからすべてのライブラリを含めることですが、すべてを除きますロケールスクリプト(一つだけは後に別のバンドル内の言語に基づいて追加されるので):
bundles.Add(new Bundle("~/bundles/scripts")
.Include("~/wwwroot/lib/angular/angular.js") // Has to be first
.IncludeDirectoryWithExclusion("~/wwwroot/lib", "*.js", true, "*.locale.*.js"));
これは、あなたがangular.min.jsとangular.jsの両方を持っている場合、正しく振る舞うとでunminifiedバージョンが追加されますデバッグし、r内の既存の.min.jsを使用するエレアース。
ありがとう!この回答は、私がバンドルしていた問題も解決しました。 –
- 1. ASP.NET MVCで "<%="、 "<%:" "<%#"の違いは何ですか?
- 2. 私は私の<strong>ASP.NET MVC</strong>アプリケーションで<strong>DI</strong>ため<strong>Ninject</strong>を使用していMVCアプリケーション
- 3. 私は2つの機能</p> <pre><code>void foo() { std::cout << 1 << std::endl; } void bar() { std::cout << 2 << std::endl; } </code></pre> <p>をお持ちの場合は2個の関数のC++
- 4. Heredoc <<<または<<?
- 5. 私は形でマルチファイルアップロードコントロールの<strong><em>N</em></strong>番号を持っているMVC
- 6. 私は<code>Emulator Android BlueStack</code></p> <p><code>IISExpress ASP.NET</code>で<code>ASP.NET IISExpress</code>を使用したい
- 7. ルーティングレガシーリンク私は</p> <blockquote> <p>/signedin/mypage.aspx?my_key=152372</p> </blockquote> <p>にこのような何かをリダイレクトしたい
- 8. は私がこの</p> <p><strong>ページ名</strong>ようなページIDの
- 9. は、どのように私は<code>string</code>あるこの</p> <pre><code>var alldest = cc.returnallfullDestinations(mainElement).Split('|'); </code></pre> <p><code>returnallfullDestionations</code>のようなデータを取得していますC#
- 10. バンドル名にファイル拡張子を付ける方法はありますか?バンドル名は、この作品だけ<code>"~/style"</code>ですが、ファイル拡張子で、それは常に私がCSSやJSのサーバー検索を疑う404を返す場合</p> <pre><code>bundles.Add( new StyleBundle("~/style.css").Include( //... )); </code></pre> <p>:私はこのようなバンドルを定義しているしたいと思います
- 11. は、私は、マルチモジュールが<code>moduleB</code>が<code>moduleA</code>に依存</p> <pre><code>root \ moduleA \ moduleB \ moduleC \ </code></pre> <p>に従うよう構築のGradle持つモジュールが最後
- 12. 私はこのような<code>ViewModel</code>持って右にShowDialog
- 13. Ninjectコンテキストは、私は一般的なインタフェース<code>IRepository<T></code>との2つの実装<code>xrmRepository<T></code>と<code>efRepository<T></code></p> <p>を持っているワット/オープンジェネリック
- 14. Gitは<<<<<<< HEADをファイルに追加し続けます
- 15. は、どのように私は、変数</p> <pre><code>int x = 2; </code></pre> <p>とリストを持っている
- 16. 最善の方法は、私が<strong><code>Object1</code></strong>と<strong><code>Object2</code></strong>のような2つの複合オブジェクトを持つ2つの複雑なオブジェクト
- 17. 私は3つのクラス(<strong>カー</strong>(スーパー)、<strong>CarToRent</strong>、および<strong>CarToSell</strong>を持っているJavaの
- 18. Postgresはによってタプルを見つけて、私は2つのテーブル</p> <p><strong>テーブル</strong><br> ID <br> タイトル<br> 年</p> <hr> <p><strong>表B</strong><br> ID <br> を持っている他のテーブル
- 19. THREE.Camera.prototype.lookAt</ <() -</ <はどういう意味ですか?
- 20. は、私はこのような背後にあるコードでCSSを変更しようとしています。..</p> <p>..私は、これはDIV持っ</p> <p><code><div id="downloadableProducts" runat="server"><a href="#">Downloadedable Products</a></div></code></p> <p>を私のaspxページでasp.net
- 21. CSS:</p> <p><a href="http://jsfiddle.net/h2rsJ/2/" rel="nofollow noreferrer">http://jsfiddle.net/h2rsJ/2/</a></p> <p>、私はそれはこのようになりたい::イムがこれを持つこの権利
- 22. は私が</p> <pre><code>List[(String, Object)] </code></pre> <p>どのように私はこのリストをループ<code>for</code>を使用することができ、以下のようなサンプル<code>List</code>を持ってScalaの
- 23. がどのように要素を削除して、今、私はこのHTMLを解析したい私はこの</p> <pre><code>Hello<i class="emoji emoji_smile" title=":smile:"></i><i class="emoji emoji_angry" title=":angry:"></i>World </code></pre> <p>のようなHTMLスニペットを持って
- 24. Mavenの - 私は私が持っているプロジェクトのそれぞれを構築するときにどのよう</li> <li>DataComponents</li> <li>ServiceComponents </ul> <p></li>を</p> <ul> <li>WebComponentsを私は3つのMavenを持って一つのプロジェクト
- 25. のLINQのINステートメントは、私は2つのテーブル</p> <p><strong>契約</strong></p> <p>IDを持って
- 26. は、私は2つのプロジェクト<strong>OSBのEclipse</strong>上<strong></strong>と<strong>B</strong>を持っている日食
- 27. だから私はこのようなアクションから<code>FileContentResult</code>を返すよASP.NET MVC
- 28. JSON要素は、私はEJSに初心者です、と私はここで、この</p> <pre><code><input class="form-control" id="inputName" type="text" <% { %>value='<%= JSON.stringify(result.firstname) %>'<% } %> </code></pre> <p>のように入力タグを持つ、印刷データが空である
- 29. は、私は私の<strong><em>カスタムウィジェットコードから</em></strong>を追加<strong><em>QGridLayout</em></strong>で、QGridLayout
- 30. は、私は次のdiv要素に</p> <pre><code><div class="top"> <div class="inner1"></div> <div class="inner2"></div> <div class="inner3"></div> </div> </code></pre> <p>を持つdivのフィット残りの高さ
なぜあなたはそのディレクトリからCSSファイルを移動しないのですか? –
もちろんこのファイルには別のバンドルを指定することもできますが、すべてのファイルを1つのディレクトリに入れておく必要があります。バンドルから除外します。 – xurca
たくさんありますかのファイルですか?少数のファイルがある場合は、個々のcssを個別に登録することができます。 –