如何防止Visual Studio在applicationhost.config中修改IIS Express站点的物理路径? [英] How do I prevent Visual Studio from modifying the IIS Express site's phyical path in applicationhost.config?

查看:224
本文介绍了如何防止Visual Studio在applicationhost.config中修改IIS Express站点的物理路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio Web应用程序项目,由于某些原因,该项目将文件从多个项目复制到单独的输出目录.我想将此输出目录用作关联的IIS Express站点的根.在IIS Express的applicationhost.config文件中,我可以将关联站点的物理路径设置为正确的目录.我将其设置如下:

I have a Visual Studio web application project that, for certain reasons, copies files from multiple projects to a separate output directory. I want to use this output directory as the root of the associated IIS Express site. In IIS Express' applicationhost.config file, I can set the associated site's physical path to the correct directory. I'll set it like this:

<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没有任何迹象表明它已经做到了.在Visual Studio将其弄乱之后,<virtualDirectory>元素的外观如下:

However, when I reopen the project, Visual Studio overwrites my specified physical path, reverting it to the project's own directory. Even worse, Visual Studio gives me no indication that it has done this. Here's how the <virtualDirectory> element looks after Visual Studio messes it up:

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

如何防止Visual Studio覆盖此路径?

How can I prevent Visual Studio from overwriting this path?

推荐答案

Visual Studio 2013和2015不会更改选项'Override applicationpool URL'的物理路径:

Visual Studio 2013 and 2015 does not change the physical path for the option 'Override applicationpool 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>

只需将您的默认块复制到上面,将其直接粘贴在下面并进行一些更改.更改nameidphysicalPath,并使用其他子域覆盖URL.就我而言debug:

Just copy the your default block above, paste it directly below and make some changes. Change the name, id, physicalPath and override the URL with the additional subdomain. In my case debug:

<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.对我有用.

Now, when I start VS and run the IIS Express, Visual studio does not change the physicalPath in the applicationhost.config of the overwritten URL. That works for me.

Visual Studio 2015的提示:Visual Studio 2015使用文件YourProject/.vs/config/applicationhost.config并在每次打开环境时覆盖它.打开*.proj文件并设置以下条目:

Hint for Visual Studio 2015: Visual Studio 2015 uses the file YourProject/.vs/config/applicationhost.config and overrides it every time you open the environment. Open your *.proj file and set the following entry:

<UseGlobalApplicationHostFile>true</UseGlobalApplicationHostFile>

通过这种配置,IIS Express使用位于以下位置的全局应用程序主机文件:%userprofile%\documents\iisexpress\config\applicationhost.config.

With this configuration, the IIS Express uses your global application host file located at: %userprofile%\documents\iisexpress\config\applicationhost.config.

这篇关于如何防止Visual Studio在applicationhost.config中修改IIS Express站点的物理路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆