7

VS2010/IIS 7.5 でサイトを開発するとき、Web Deploy を使用して自分のマシンから開発サイト サーバーにサイトを公開しています。

このサイトには約 40 個の仮想ディレクトリがあり、展開中にサーバー上にそれらを自動的に作成したいと考えています。これを行う簡単な方法はありますか?

ファイルまたはデータベースからリストをロードしてオンデマンドで作成する小さなアプリを作成することを検討しています。私の開発マシンでは、Web サーバーとはディレクトリの物理パスが異なります。これもまた、問題を引き起こします。

4

3 に答える 3

6

Web デプロイに MSBuild を使用している場合は、仮想ディレクトリの作成に使用できる CustomBuildTask を .net に記述できます。

カスタム ビルド タスクを作成して使用する方法に関するリソースは多数ありますが、カスタム ビルド タスクを使用して仮想ディレクトリを作成するために使用するコードは次のとおりです。

public void CreateVirtualDirectory()
{

    DirectoryEntry oDE = new DirectoryEntry("IIS://" +
            this._strServerName + "/W3SVC/" + _webSiteID + "/Root");


    //Get Default Web Site
    DirectoryEntries oDC = oDE.Children;

    //Add row to schema
    DirectoryEntry oVirDir = oDC.Add(this._strVDirName,
                oDE.SchemaClassName.ToString());

    //Commit changes for Schema class File
    oVirDir.CommitChanges();


    //Set virtual directory to physical path
    oVirDir.Properties["Path"].Value = this._strPhysicalPath;

    //Set read access
    oVirDir.Properties["AccessRead"][0] = true;

    //Set the default docs
    oVirDir.Properties["EnableDefaultDoc"][0] = true;
    oVirDir.Properties["DefaultDoc"][0] = "default.aspx";

    //set the name
    oVirDir.Properties["AppFriendlyName"][0] = this._strVDirName;

    //do it
    oVirDir.Invoke("AppCreate", true);


    //set the application pool
    if (!string.IsNullOrEmpty(_strApplicationPool))
    {
        object[] param = { 0, _strApplicationPool, true };
        oVirDir.Invoke("AppCreate3", param);
        oVirDir.Properties["AppIsolated"][0] = "2";
    }

    //Save all the changes
    oVirDir.CommitChanges();
}
于 2010-11-19T21:19:31.787 に答える
1

WebDeploy に対してカスタム プログラミングを行ったことはありませんが、そのための API があるという参照を見てきました。公式ドキュメントが見つからないようですが、おそらくこのブログ + サンプル アプリが手がかりになるかもしれません: Web Deploy API Web Application

于 2010-11-19T20:52:45.190 に答える