IIS CLI generate applicationhost.config with site for my project
我有一个包含多个项目的 C# 解决方案,其中一个是由 IIS 运行的 Web 服务器。我在该项目的 csproj 文件中设置了 <UseGlobalApplicationHostFile>True</UseGlobalApplicationHostFile>。
当我打开 Visual Studio 时,它会在 ~/Documents/IISExpress/config/applicationhost.config:
中生成它
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<sites>
<site name=“WebSite1” id=“1” serverAutoStart=“true”> <virtualDirectory path=“/” physicalPath=“%IIS_SITES_HOME%\\WebSite1″ /> </application> <bindings> <binding protocol=“http” bindingInformation=“:8080:localhost” /> </bindings> </site> <site name=“SealingService” id=“2”> <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> <virtualDirectoryDefaults allowSubDirConfig=“true” /> </sites> |
我希望能够从命令行使用 IIS Express 运行我的项目(用于构建服务器集成测试目的)。如何从命令行生成 applicationhost.config 的 SealingService 站点部分(无需打开 Visual Studio)?
我试过运行
1
|
“C:\\Program Files (x86)\\IIS Express\\iisexpress.exe”
|
在我的解决方案文件夹中,但它只生成 WebSite1 部分。
- 我认为那是严格意义上的 VS 功能。为什么要”生成”它?您始终可以将 applicationHost.config 的副本放在您的存储库和 CI 机器上,从命令行运行 IIS Express 以读取该配置文件。
- @LexLi 我可以这样做,但是如何为本地和 CI 机器设置不同的 physicalPath ?我们也希望能够在本地按需运行测试,理想情况下无需更改配置文件。
- 在路径中保留一个环境变量,然后在您的 CI 序列中将其设置为确切的文件夹,我认为它应该可以工作。
- @LexLi 我已经让它工作了,谢谢!
- 该文件默认不存在。它仅通过使用 Visual Studio 生成,而不是仅从构建中生成。只有在使用 IIS Express 运行调试器时才会生成它。因此,要真正从命令行运行它,您需要一种生成 applicationHost.config 文件的方法,就像 VS 一样。这就是问题所在。
如果我理解正确,您要做的是将您指定的部分添加到 ~/Documents/IISExpress/config/applicationhost.config 文件中。
您可以使用 AppCmd.exe 命令行工具执行此操作:
1
2 3 |
“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 绑定。
如果您使用 x86 版本的 IIS Express,您会在 C:\\\\\\\\Program Files (x86)\\\\\\\\IIS Express\\\\\\\\appcmd.exe 中找到 AppCmd
- 看起来它会编辑文件,但是首先生成文件呢?
- @ScottH 您可以首先运行 iisexpress.exe 来生成文件
- 这个文件怎么能在任意位置生成,比如visual studio是怎么在它的.vs用户目录下生成文件的?
来源:https://www.codenong.com/45640323/