Microsoft のいくつかのインストーラーを調べて、WIF ランタイムの存在をどのように検出したかを確認した後、上記の回答からのレジストリ チェックの提案を使用しました。
これが私が行ったものです:
/// <summary>
/// Determines if WIF is installed on the machine.
/// </summary>
public static class WifDetector
{
/// <summary>
/// Gets a value indicating that WIF appears to be installed.
/// </summary>
public static bool WifInstalled { get; private set; }
static WifDetector()
{
WifInstalled = IsWifInstalled();
}
private static bool IsWifInstalled()
{
try
{
//return File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
// "Reference Assemblies\\Microsoft\\Windows Identity Foundation\\v3.5\\Microsoft.IdentityModel.dll"));
//The registry approach seems simpler.
using( var registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows Identity Foundation") ??
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows Identity Foundation") )
{
return registryKey != null;
}
}
catch
{
//if we don't have permissions or something, this probably isn't a developer machine, hopefully the server admins will figure out the pre-reqs.
return true;
}
}
}
次に、ベースページまたはマスターページで値を確認し、ユーザーに知らせます。実際のチェックは型初期化子で 1 回だけ実行され、その後は単純な静的プロパティへのアクセスになります。
private void CheckWifInstallation()
{
if (!WifDetector.WifInstalled)
{
var alert = new ClientSideAlert(
"This application requires the Windows Identity Foundation runtime to be installed on the webserver:\n");
alert.AddMessageLine("Please install the appropriate WIF runtime for this operating system by visiting:\n");
alert.AddMessageLine("http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=17331 \n");
alert.AddMessageLine("or simply search for 'WIF runtime install'\n");
alert.AddMessageLine("Thanks, and have a nice day!'");
alert.Display(Page);
}
}
開発者のマシン用の派手な Web 展開パッケージはありません。ソースから取得して実行するだけです。これにより、このライブラリを使用していない開発者は、YSOD やあいまいなアセンブリの読み込みエラーが発生したときに時間を無駄にすることがなくなります。
提案をありがとう。