gpt4 book ai didi

azure - 如何区分虚拟机代码中的hyperv和azure?

转载 作者:行者123 更新时间:2023-12-02 06:50:26 25 4
gpt4 key购买 nike

我有一个可以在 Azure 和 Hyper-V 上运行的虚拟机。

我有一些代码只能在 azure 中执行。但我无法找到区分 azure 和 Hyper-V 的方法。

最佳答案

就个人而言,我更喜欢在 web.config 文件中使用配置属性。然后,您可以为 Azure 和 HyperV 环境分别进行两个不同的发布转换。

例如,我们在依赖 AzureStorage 时对我们的解决方案执行类似的操作,并将其包含在 Web.config 的 appSettings 部分中:

<add key="UseAzureStorage" value="false" />

然后在 web.config 转换中,您将拥有:

<add key="UseAzureStorage" value="true" xdt:Locator="Match(key)" xdt:Transform="Replace"/>

此外,如果您在 Azure 中使用云服务,则可以使用 RoleRoot 环境变量。

http://blog.toddysm.com/2011/03/what-environment-variables-can-you-use-in-windows-azure.htmlMSDN:http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx

关于azure - 如何区分虚拟机代码中的hyperv和azure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com