2014-01-30 44 views
17

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

<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中的覆盖这条道路?

回答

2

我无法阻止VS重写MySiteName的physicalPath,但作为一种解决方法,我添加了另一个具有不同路径的应用程序部分(可以说“NewPath”),并且没有更新VS以使用csproj下的此路径网站属性。在这种情况下,如果您在导航到新端点(​​)时调试它将自动打开旧URL上的浏览器(http://localhost:63470/),一切都会正常工作,VS不会恢复此操作。

因此,新的配置是这样的:

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

此解决方案在VS2015中不起作用。重新启动VS2015后,环境再次覆盖复制的应用程序部分中的physicalPath。 – Simon

4

的Visual Studio 2013年和2015年不改变物理路径的选择 '覆盖applicationpool URL':

enter image description here

文件%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,id,physicalPath并用其他子域覆盖URL。在我的情况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快递时,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

相关问题