どこかで、構成設定を使用して、特定の環境で必要な動作を示す必要があります ( IsDebuggingEnabledプロパティを使用できると思いますが、カスタム構成設定の方が柔軟です)。
考えられるテクニックは 2 つあります。
オプション1
UrlHelper
関連する構成設定を取得するための独自の拡張メソッドを作成できます。ビューコードは、構成の知識から隔離されます。たとえば、次のようになります。
<script src="@Url.StaticContent("~/Scripts/jquery.someScript.js")" type="text/javascript"></script>
実装例を次に示します (未テスト):
public static class UrlHelperExtensions
{
public static string StaticContent(this UrlHelper urlHelper, string contentPath)
{
if (!VirtualPathUtility.IsAppRelative(contentPath))
{
throw new ArgumentException("Only use app relative paths");
}
// TODO: Further checks required - e.g. the path "~" passes the above test
if (UseRemoteServer)
{
// Remove the initial "~/" from the content path
contentPath = contentPath.Substring(2);
return VirtualPathUtility.Combine(RemoteServer, contentPath);
}
return urlHelper.Content(contentPath);
}
private static string RemoteServer
{
get
{
// TODO: Determine based on configuration/context etc
return null;
}
}
private static bool UseRemoteServer
{
get
{
return !string.IsNullOrWhiteSpace(RemoteServer);
}
}
}
オプション 2
Combresのようなものを使用する代わりに、Combres の XML 構成ファイルを変換して環境ごとに構成を変更することもできます。