私はここ数日、これについてかなり多くのことを読んできました.Webセットアッププロジェクトを作成し、カスタムアクションなどでそれを変更する方法に関する多くの情報があるようです.私はこれまでのところ持っています.これについては、次のリンクを使用してください。
http://weblogs.asp.net/scottgu/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005 http://msdn.microsoft.com/en-us/library/ms525598 .aspx http://www.dreamincode.net/forums/topic/231074-setup-and-deployment-in-visual-studio-2010/ http://www.codeproject.com/Articles/146626/Extending-Visual- Studio-セットアップ-プロジェクト
ただし、 [インストール アドレス] アクション ([開始] の下) で提供されるドロップダウン リストから選択するのではなく、ユーザーが新しいサイトを作成できるように、ユーザー インターフェイスを具体的に変更する方法についてはあまりないようです。それに加えて、新しいアプリケーション プールを作成する方法のコードに出くわしましたが、UI が最初にリストから 1 を選択するオプションをユーザーに与えるのを止める方法はありません。
現時点では、インストーラーは次のようになっています。
ご覧のとおり、ユーザーには現在 3 つのフィールドがあります。サイト、仮想ディレクトリ、およびアプリケーション プール。サイトとアプリケーション プールは、既存のオプションを含むリストです。サイト ドロップダウン リストの場合、実際にはこれをテキスト ボックスにして、ユーザーが作成したい Web サイトの名前を入力できるようにしたいと考えています。アプリケーション プールの場合、カスタム アクションがアプリケーション プールを自動的に作成し、それに仮想ディレクトリを割り当てるため、これを完全に消したいと思います (うまくいけば)。
アプリ プール、仮想ディレクトリを作成し、それをアプリ プールに割り当てるためのコード (まだテストされていません) は既にありますが、必要に応じて UI を編集する方法がわかりません。「インストール アドレス」ステップを削除して、独自のカスタム ステップを作成する必要がありますか?
アプリ プールの作成、仮想ディレクトリの作成、およびアプリ プールへの仮想ディレクトリの割り当てのための以下のコード:
//Properties for user input
private string targetSite { get { return this.Context.Parameters["targetsite"]; }}
private string targetVirtualDir { get { return this.Context.Parameters["targetvdir"]; } }
private string targetDirectory { get { return this.Context.Parameters["targetdir"]; } }
private const string ApplicationPool = "TestWebAppAP";
private const string BasePath = "IIS://Localhost/W3SVC/1/Root";
private const string AppPoolsAddress = "IIS://Localhost/W3SVC/AppPools";
//Install
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
if (targetSite == null) throw new InstallException("IIS site name not specified");
else
{
CreateApplicationPool();
CreateVirtualDir();
AssignVDirtoAppPool();
}
}
//Create Application Pool
private void CreateApplicationPool()
{
try
{
DirectoryEntry NewPool;
DirectoryEntry AppPools = new DirectoryEntry(AppPoolsAddress);
NewPool = AppPools.Children.Add(ApplicationPool, "IIsApplicationPool");
NewPool.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show("Failed to create new application pool \" " + ApplicationPool + "\". Error: " + ex.Message);
throw new InstallException("Failed to create app pool", ex);
}
}
//Create Virtual Directory
private void CreateVirtualDir()
{
try
{
DirectoryEntry site = new DirectoryEntry(BasePath);
string className = site.SchemaClassName.ToString();
if (className.EndsWith("Server") || className.EndsWith("VirtualDir"))
{
DirectoryEntries vdirs = site.Children;
DirectoryEntry newVDir = vdirs.Add(targetVirtualDir, (className.Replace("Service", "VirtualDir")));
newVDir.Properties["Path"][0] = targetDirectory;
newVDir.Properties["AccessScript"][0] = true;
newVDir.Properties["AppFriendlyName"][0] = targetVirtualDir;
newVDir.Properties["AppIsolated"][0] = "1";
newVDir.Properties["AppRoot"][0] = "/LM" + BasePath.Substring(BasePath.IndexOf("/", ("IIS://".Length)));
newVDir.CommitChanges();
}
else
{
MessageBox.Show("Failed to create virtual directory. It can only be created in a site or virtual directory node.");
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to create virtual directory \"" + targetVirtualDir + "\". Error: " + ex.Message);
throw new InstallException("Failed to create virtual directory", ex);
}
}
//Assign virtual directory to app pool
private void AssignVDirtoAppPool()
{
try
{
DirectoryEntry vDir = new DirectoryEntry(BasePath);
string className = vDir.SchemaClassName.ToString();
if(className.EndsWith("VirtualDir"))
{
object[] param = { 0, ApplicationPool, true };
vDir.Invoke("AppCreate3", param);
vDir.Properties["AppIsolated"][0] = "2";
}
else
{
MessageBox.Show("Failed to assign to application pool. Only virtual directories can be assigned to application pools.");
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to assign virtual directory \"" + targetVirtualDir + "\" to application pool \"" + ApplicationPool + "\". Error: " + ex.Message);
throw new InstallException("Failed to assign virtual directory to application pool", ex);
}
}