22

特定の理由で、複数のプロジェクトから別の出力ディレクトリにファイルをコピーする Visual Studio Web アプリケーション プロジェクトがあります。この出力ディレクトリを関連する IIS Express サイトのルートとして使用したいと考えています。IIS Express の applicationhost.config ファイルで、関連付けられたサイトの物理パスを正しいディレクトリに設定できます。次のように設定します。

<site name="MySiteName" id="42">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="c:\my\desired\path" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:63470:localhost" />
    </bindings>
</site>

ただし、プロジェクトを再度開くと、指定した物理パスが Visual Studio によって上書きされ、プロジェクト独自のディレクトリに戻されます。さらに悪いことに、Visual Studio は、これが行われたことを示しません。<virtualDirectory>Visual Studio がめちゃくちゃにした後の要素は次のようになります。

        <virtualDirectory path="/" physicalPath="c:\path\to\project" />

Visual Studio がこのパスを上書きしないようにするにはどうすればよいですか?

4

2 に答える 2

4

Visual Studio 2013 および 2015 では、[アプリケーション プール URL を上書きする] オプションの物理パスは変更されません。

ここに画像の説明を入力

デフォルトでは、ファイル%userprofile%\documents\iisexpress\config\applicationhost.configは次のようになります。

<site name="MyWebSite" id="1477659296">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Projects\MyWebSite" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:62238:localhost" />
        <binding protocol="http" bindingInformation="*:62238:*" />
    </bindings>
</site>

上のデフォルト ブロックをコピーし、すぐ下に貼り付けて、いくつかの変更を加えるだけです。、を変更しname、追加のサブドメインで URL をオーバーライドします。私の場合:idphysicalPathdebug

<site name="MyWebSiteOverwritten" id="99999999">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Projects\DifferentPath" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:62238:debug.localhost" />
    </bindings>
</site>

これで、VS を起動して IIS Express を実行すると、Visual Studio は上書きされた URL の applicationhost.config の physicalPath を変更しません。それは私にとってはうまくいきます。

Visual Studio 2015 のヒント: Visual Studio 2015 はファイルYourProject/.vs/config/applicationhost.configを使用し、環境を開くたびにオーバーライドします。ファイルを開き*.proj、次のエントリを設定します。

<UseGlobalApplicationHostFile>true</UseGlobalApplicationHostFile>

この構成では、IIS Express は次の場所にあるグローバル アプリケーション ホスト ファイルを使用します%userprofile%\documents\iisexpress\config\applicationhost.config

于 2015-06-17T07:12:04.073 に答える