.net - 控制台应用程序的配置转换未使用 Azure Pipelines 部署到 Azure 应用服务
问题描述
当我尝试将控制台应用程序部署到我们的舞台环境时,配置转换未正确应用。我知道最终格式需要是 {ConsoleProjectName}.exe.config,并且发布管道的日志似乎向我显示了预期的结果,但是当我查看 Web 作业的配置文件时(以及何时作业已执行),它使用的是发布配置而不是暂存配置。
在项目中,我有两个应用程序配置文件,用于要部署到的环境:
App.Release.config
App.Stage.Config
在我的 csproj 文件中,我已将其设置为将这些文件复制到预期的输出名称(LegendMaintenance.exe.{Environment}.config):
<Target Name="AfterBuild">
<Copy SourceFiles="$(OutDir)\App.Stage.Config" DestinationFiles="$(OutDir)\$(AssemblyName).exe.Stage.config">
</Copy>
<Copy SourceFiles="$(OutDir)\App.Release.Config" DestinationFiles="$(OutDir)\$(AssemblyName).exe.Release.config">
</Copy>
</Target>
当我在 Azure DevOps 中构建它时,我可以看到文件从它创建的工件中正确放置。我还确认这些文件的内容是正确的:
当我创建我的发布版本时,我检查了 Transform XML 参数:
当我检查构建日志时,看起来一切都在按预期进行转换:
2020-04-29T22:21:01.7754752Z [command]D:\a\_tasks\AzureRmWebAppDeployment_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX\4.163.5\ctt\ctt.exe s:D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config t:D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.Release.config d:D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config pw i verbose
2020-04-29T22:21:01.9071810Z Start tranformation to 'D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config'.
2020-04-29T22:21:01.9072649Z Source file: 'D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config'.
2020-04-29T22:21:01.9073219Z Transform file: 'D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.Release.config'.
2020-04-29T22:21:01.9073943Z Transformation task is using encoding 'System.Text.UTF8Encoding'. Change encoding in source file, or use the 'encoding' parameter if you want to change encoding.
2020-04-29T22:21:01.9074503Z Executing Replace (transform line 3, 21)
2020-04-29T22:21:01.9074838Z on /configuration/connectionStrings
2020-04-29T22:21:01.9075309Z Applying to 'connectionStrings' element (no source line info)
2020-04-29T22:21:01.9075676Z Replaced 'connectionStrings' element
2020-04-29T22:21:01.9076209Z Done executing Replace
2020-04-29T22:21:01.9076565Z Executing Replace (transform line 7, 46)
2020-04-29T22:21:01.9076941Z on /configuration/appSettings/add[@key='Environment']
2020-04-29T22:21:01.9077340Z Applying to 'add' element (no source line info)
2020-04-29T22:21:01.9077940Z Replaced 'add' element
2020-04-29T22:21:01.9078245Z Done executing Replace
...
2020-04-29T22:21:01.9114114Z [command]D:\a\_tasks\AzureRmWebAppDeployment_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX\4.163.5\ctt\ctt.exe s:D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config t:D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.Stage.config d:D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config pw i verbose
2020-04-29T22:21:02.0382404Z Start tranformation to 'D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config'.
2020-04-29T22:21:02.0383056Z Source file: 'D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.config'.
2020-04-29T22:21:02.0383676Z Transform file: 'D:\a\_temp\temp_web_package_XXXXXXXXXXXXXXXX\LegendMaintenance.exe.Stage.config'.
2020-04-29T22:21:02.0384223Z Transformation task is using encoding 'System.Text.UTF8Encoding'. Change encoding in source file, or use the 'encoding' parameter if you want to change encoding.
2020-04-29T22:21:02.0384646Z Executing Replace (transform line 3, 21)
2020-04-29T22:21:02.0384907Z on /configuration/connectionStrings
2020-04-29T22:21:02.0385184Z Applying to 'connectionStrings' element (no source line info)
2020-04-29T22:21:02.0385609Z Replaced 'connectionStrings' element
2020-04-29T22:21:02.0385828Z Done executing Replace
2020-04-29T22:21:02.0386197Z Executing Replace (transform line 7, 44)
2020-04-29T22:21:02.0386478Z on /configuration/appSettings/add[@key='Environment']
2020-04-29T22:21:02.0386776Z Applying to 'add' element (no source line info)
2020-04-29T22:21:02.0387012Z Replaced 'add' element
2020-04-29T22:21:02.0387299Z Done executing Replace
2020-04-29T22:21:02.0388971Z Executing Replace (transform line 12, 83)
2020-04-29T22:21:02.0389270Z on /configuration/system.net/mailSettings/smtp
2020-04-29T22:21:02.0389552Z Applying to 'smtp' element (no source line info)
2020-04-29T22:21:02.0389837Z Replaced 'smtp' element
2020-04-29T22:21:02.0390034Z Done executing Replace
...
2020-04-29T22:21:09.0855271Z Info: Updating file (legendjobboard\app_data\jobs\triggered\JobBoardWebConsole\LegendMaintenance.exe.config).
但是,当我在我的应用服务中检查 LegendMaintenance.exe.config 文件时,它显示的是发布值而不是暂存值。
需要注意的一件有趣的事情是 app.config 本身似乎已按预期进行了转换(它使用了 Staging 配置)。我可能可以通过以某种方式重命名该文件来解决它,但我不明白为什么它不能按原样工作,特别是因为 Azure DevOps 日志似乎表明它是。
另请注意,此过程适用于我们的网站部署任务,只是控制台项目/Web 作业存在问题。
我错过了什么?有什么方法可以对 Azure DevOps 中的 Web 部署过程进行故障排除?或者有没有更好的方法来做到这一点?
编辑:这是我从构建输出下载的工件的配置(值被审查,因为它们基本上都是敏感的):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="JobBoardDbConnection"
connectionString="Server=tcp:aaa.database.windows.net,1433;Database=aaa;User ID=aaa@aaa;Password=aaa;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="Environment" value="production"/>
<add key="MaxWidth" value="3000" />
<add key="MaxHeight" value="3000" />
<add key="ResumeCache" value="D:\aaa\aaa\aaa\aaa\aaa\"/>
<add key="ResumeFiles" value="D:\aaa\aaa\aaa\aaa\aaa\"/>
<add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="IndeedXmlFileLocation" value="D:\aaa\aaa\aaa\aaa\aaa\aaa"/>
<add key="SnagAJobXmlFileLocation" value="D:\aaa\aaa\aaa\aaa\aaa\aaa"/>
<add key="ZipRecruiterXmlFileLocation" value="D:\aaa\aaa\aaa\aaa\aaa\aaa"/>
<add key="IndustryXmlFileLocation" value="D:\aaa\aaa\aaa\aaa\aaa\aaa"/>
<add key="DefaultXmlPublisher" value="aaa" />
<add key="DefaultXmlPublisherUrl" value="http://aaa" />
<add key="ArenaIOApiUrl" value="https://aaa"/>
<add key="ArenaIOApiUserName" value="aaa"/>
<add key="ArenaIOApiPassword" value="aaa"/>
<add key="ArenaExceptionsEmail" value="aaa@aaa.com,aaa@aaa.com" />
<add key="JobFeedDirectory" value="D:\aaa\aaa\aaa\aaa\aaa"/>
<add key="IndeedApplyApiToken" value="aaa"/>
<add key="IndeedApplySecretKey" value="aaa"/>
<add key="IndeedApplyPostUrl" value="https://aaa"/>
<add key="TwilioAccountSid" value="aaa" />
<add key="TwilioAuthToken" value="aaa" />
<add key="TwilioMessagingServiceSid" value="aaa" />
<add key="FacebookCompanyId" value="aaa" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Common" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.0.0" newVersion="5.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="RazorEngine" publicKeyToken="9ee697374c7e744a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.4.1.0" newVersion="3.4.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="SimpleInjector" publicKeyToken="984cb50dea722e99" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.0.0" newVersion="2.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.net>
<mailSettings>
<smtp from="aaa@aaa.com">
<network host="smtp.aaa.net" port="587" userName="aaa" password="aaa"
enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="JobBoard.Infrastructure.Logging" />
</extensions>
<targets>
<target name="LogFile" xsi:type="File" fileName="D:\aaa\aaa\aaa\aaa\aaa\aaa.txt"
layout="${longdate} | ${level:uppercase=true} | Message: ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="LogFile" />
</rules>
</nlog>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
LegendMaintenance.exe.Release.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings xdt:Transform="Replace">
<add name="JobBoardDbConnection" connectionString="Server=tcp:xxx.database.windows.net,1433;Database=xxx;User ID=xxx@xxx;Password=xxx;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="Environment" value="production" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ResumeCache" value="D:\xxx\xxx\xxx\xxx\xxx\" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ResumeFiles" value="D:\xxx\xxx\xxx\xxx\xxx\" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="IndeedXmlFileLocation" value="D:\xxx\xxx\xxx\xxx\xxx\xxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="SnagAJobXmlFileLocation" value="D:\xx\xxx\xxx\xxx\xxx\xxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ZipRecruiterXmlFileLocation" value="D:\xxx\xxxx\xxx\xxx\xxx\xxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="IndustryXmlFileLocation" value="D:\xxx\xxx\xxx\xxx\xxx\xxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ArenaIOApiUrl" value="https://xxxx.com/xxx-xxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ArenaIOApiUserName" value="xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ArenaIOApiPassword" value="xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="ArenaSecurityKey" value="xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="JobFeedDirectory" value="D:\xxx\xxxx\xxxx\xxxx\xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="IndeedApplyApiToken" value="xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="IndeedApplySecretKey" value="xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="IndeedApplyPostUrl" value="https://xxxx" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
<system.net>
<mailSettings>
<smtp from="xxx@xxx.com" xdt:Transform="Replace">
<network host="smtp.xxxx.net"
port="587"
userName="xxxx"
password="xxxxxxxx"
enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets xdt:Transform="Replace">
<target name="LogFile" xsi:type="File" fileName="D:\xxx\xxx\xxx\xxx\xxx\xxx.txt" layout="${longdate} | ${level:uppercase=true} | Message: ${message}" />
</targets>
</nlog>
</configuration>
LegendMaintenance.exe.Stage.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings xdt:Transform="Replace">
<add name="JobBoardDbConnection" connectionString="Server=tcp:yyy.database.windows.net,1433;Database=yyy;User ID=yyy@yyy;Password=yyy;Encrypt=True;TrustServerCertificate=False;Connection Timeout=300;" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="Environment" value="staging" xdt:Transform="Replace" xdt:Locator="Match(key)" />
<add key="IndeedApplyPostUrl" value="https://yyyy" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
<system.net>
<mailSettings>
<smtp from="yyy@yyy.com" deliveryMethod="SpecifiedPickupDirectory" xdt:Transform="Replace">
<specifiedPickupDirectory pickupDirectoryLocation="D:\yyy\yyy\yyy\yyy\yyy"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
解决方案
推荐阅读
- python - Django:有没有一种简单的方法可以在数据库中存储选择
- c++ - 从 c++ 函数返回引用时会发生什么?
- rust - 访问 Rust 中 Rc 的 Option 内部的结构成员
- reactjs - React - 函数作为 React 子级无效
- html - display:none 和 visibility:hidden 都不起作用
- android - VideoView 不从内部存储加载视频
- flutter - 底部工作表未显示在底部
- android - 应用程序需要重新启动才能连接到 Firebase
- css - Vue 3 CLI 聊天应用程序引导文本不会向左对齐
- reporting-services - SSRS 有任何页面限制来呈现吗?