2017-08-11 98 views
9

我有一个C#解决方案,有几个项目,其中一个是IIS运行的Web服务器。我在该项目的csproj文件中设置了<UseGlobalApplicationHostFile>True</UseGlobalApplicationHostFile>IIS CLI为我的项目生成applicationhost.config和网站

当我打开Visual Studio中,它会产生这样在〜/文档/ IISExpress /配置/对ApplicationHost.config:

<sites> 
     <site name="WebSite1" id="1" serverAutoStart="true"> 
      <application path="/"> 
       <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" /> 
      </application> 
      <bindings> 
       <binding protocol="http" bindingInformation=":8080:localhost" /> 
      </bindings> 
     </site> 
     <site name="SealingService" id="2"> 
      <application path="/" applicationPool="Clr4IntegratedAppPool"> 
       <virtualDirectory path="/" physicalPath="C:\Users\sehch\Documents\Paragon\ParagonCore\servers\SealingService\SealingService" /> 
      </application> 
      <bindings> 
       <binding protocol="http" bindingInformation="*:61800:localhost" /> 
       <binding protocol="https" bindingInformation="*:44300:localhost" /> 
      </bindings> 
     </site> 
     <siteDefaults> 
      <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" /> 
      <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" /> 
     </siteDefaults> 
     <applicationDefaults applicationPool="Clr4IntegratedAppPool" /> 
     <virtualDirectoryDefaults allowSubDirConfig="true" /> 
    </sites> 

我希望能够与IIS快递从命令行运行我的项目(用于构建服务器集成测试目的)。如何从命令行(不打开Visual Studio)生成applicationhost.config的SealingService网站部分?

我已经尝试运行

"C:\Program Files (x86)\IIS Express\iisexpress.exe" 
在我的解决方案文件夹

,但它只能产生WebSite1部分。

+0

我认为这是严格意义上的VS功能。你为什么要“生成”?你总是可以在你的仓库和CI机器上放置一个'applicationHost.config'副本,从命令行运行IIS Express来读取该配置文件。 –

+1

@LexLi我可以这样做,但是如何为本地和CI机器设置不同的'physicalPath'?我们希望能够根据需要在本地运行测试,理想情况下不需要更改配置文件。 –

+3

在路径中留下一个环境变量,然后将其设置到CI序列中的确切文件夹中,我认为它应该起作用。 –

回答

0

如果我理解正确,您要做的是将您指定的部分添加到〜/ Documents/IISExpress/config/applicationhost.config文件中。

您可以使用AppCmd.exe命令行工具做到这一点:

"C:\Program Files\IIS Express\appcmd.exe" add site /name:SealingService /bindings:"http/*:61800:localhost" /physicalPath:"C:\Users\sehch\Documents\Paragon\ParagonCore\servers\SealingService\SealingService" 
"C:\Program Files\IIS Express\appcmd.exe" set site /site.name:SealingService /[path='/'].applicationPool:Clr4IntegratedAppPool 
"C:\Program Files\IIS Express\appcmd.exe" set site /site.name:SealingService /+bindings.[protocol='https',bindingInformation='*:44300:localhost'] 

随着第一个命令我们创建网站,设置其http绑定及其物理路径;与第二个我们设置应用程序池与所需的一个;并与第三个我们添加https绑定

如果您使用IIS快递x86版本,你会发现在APPCMD C:\ Program Files文件(x86)的\ IIS快递\ Appcmd.exe的

+0

这看起来像它会编辑文件,但首先生成文件呢? –

+0

@ScottH你可以运行iisexpress.exe来首先生成文件 –

相关问题