我们正在测试 Octopus Deploy,所以我们制作了一个示例 web.config 文件,我们在不同的环境中安装和转换。web.config 转换和自定义变量的使用工作正常,但我无法替换内置的 Octopus 变量。这是 web.config 中 XML 部分的示例:
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="environmentTransform" value="" />
<add key="EnvironmentVariable1" value="$OctopusEnvironmentName" />
<add key="EnvironmentVariable2" value="$(OctopusEnvironmentName)" />
<add key="EnvironmentVariable3" value="$(Octopus.Environment.Name)" />
<add key="EnvironmentVariable4" value="$Octopus.Environment.Name)" />
<add key="EnvironmentVariable5" value="$OctopusParameters["Octopus.Environment.Name"]" />
<add key="MachineVariable1" value="$Octopus.Machine.Name" />
<add key="MachineVariable2" value="#(Octopus.Machine.Name)" />
<add key="MachineVariable3" value="#OctopusMachineName" />
<add key="CustomVariable" value="CustomVariable" />
</appSettings>
这里是 web.Dev.config,以环境命名:
<appSettings>
<add key="environmentTransform" value="Dev" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
结果如下:
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="environmentTransform" value="Dev" />
<add key="EnvironmentVariable1" value="$OctopusEnvironmentName" />
<add key="EnvironmentVariable2" value="$(OctopusEnvironmentName)" />
<add key="EnvironmentVariable3" value="$(Octopus.Environment.Name)" />
<add key="EnvironmentVariable4" value="$Octopus.Environment.Name)" />
<add key="EnvironmentVariable5" value="$OctopusParameters["Octopus.Environment.Name"]" />
<add key="MachineVariable1" value="$Octopus.Machine.Name" />
<add key="MachineVariable2" value="#(Octopus.Machine.Name)" />
<add key="MachineVariable3" value="#OctopusMachineName" />
<add key="CustomVariable" value="Value for maeaint01" />
</appSettings>
如您所见,章鱼变量没有被替换。知道为什么吗?