我哪裏有下面的語句asp.mvc視圖enteres #IF調試版本配置
#if DEBUG
//section 1
//do stuff
#else
//section 2
//do other stuff
#endif
的ASP MVC視圖當在Visual Studio中,我選擇從下拉列表中發佈配置做打造,代碼仍然遍歷第1部分。
在解決方案配置屬性中,解決方案的所有子項目都設置爲發佈配置。
我不在這裏?
我哪裏有下面的語句asp.mvc視圖enteres #IF調試版本配置
#if DEBUG
//section 1
//do stuff
#else
//section 2
//do other stuff
#endif
的ASP MVC視圖當在Visual Studio中,我選擇從下拉列表中發佈配置做打造,代碼仍然遍歷第1部分。
在解決方案配置屬性中,解決方案的所有子項目都設置爲發佈配置。
我不在這裏?
理解爲您的項目有兩個完全獨立的編譯很重要。第一個是你在Visual Studio中做的一個。第二個就是ASP.NET在提供頁面之前所做的工作。如果您的視圖中的DEBUG在第二步中完成。您描述的發佈版本是第一步。因此,您的項目的調試/發佈設置完全與Web.config/ASP.NET編譯器中的調試設置無關。
此外,您的Visual Studio版本更改Web.config中的調試設置完全不合適。這是兩個獨立的彙編,一個不應該影響另一個。
另一方面,當您在Visual Studio中進行調試時,您可能完全有理由使視圖的行爲不同,並且您可以執行此操作。您只需將「if」語句移到視圖之外,並將其轉換爲由Visual Studio編譯而非ASP.NET編譯的內容。我們使用HTML幫助程序來完成此操作。例如:
/// <summary>
/// Returns the HTML to include the appropriate JavaScript files for
/// the Site.Master.aspx page, depending upon whether the assembly
/// was compiled in debug or release mode.
/// </summary>
/// <returns>HTML script tags as a multi-line string.</returns>
public static string SiteMasterScripts(this UrlHelper helper)
{
var result = new StringBuilder();
#if DEBUG
result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", helper.Content("~/Content/js/MicrosoftAjax.debug.js"));
#else
result.AppendFormat("<script src=\"{0}\" type=\"text/javascript\"></script>", helper.Content("~/Content/js/MicrosoftAjax.js"));
#endif
// etc. ...
這包括調試JS文件在調試配置在Visual Studio中運行時,但最小JS除外。
檢查您的項目設置以確保DEBUG未定義。
在您的web.config
文件中設置<compilation debug="false">
。
這似乎不工作?這對我的工作:http://stackoverflow.com/questions/2951128/c-and-asp-net-mvc-using-if-directive-in-a-view/4509854#4509854 – russau 2011-09-07 07:31:41
切換縮小和完整的javascript/css正是我使用IF IF DEBUG的原因。謝謝您的回答。 – 2009-09-09 08:50:14
由於視覺工作室弄髒了錯誤的文本塊,所以令人困惑。 – ajbeaven 2011-07-14 01:45:23
+1關於兩個編譯器的很好的解釋。現在有道理。 – ashes999 2013-04-26 10:29:55