Когда я пытаюсь развернуть свое консольное приложение в нашей рабочей среде, преобразования конфигурации применяются неправильно. Я знаю, что окончательный формат должен быть {ConsoleProjectName} .exe.config, и журналы для конвейера выпуска, похоже, показывают мне ожидаемые результаты, но когда я смотрю файл конфигурации для веб-задания (и когда задание выполнено), он использует конфигурацию выпуска, а не промежуточную конфигурацию.
В проекте у меня есть два файла конфигурации приложения для сред, в которых я хочу развернуть:
App.Release.config
App.Stage.Config
В моем файле csproj я настроил его для копирования этих файлов с ожидаемым именем вывода (LegendMain maintenance.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 , Я вижу, что файлы размещены правильно по созданным им артефактам. Я также подтвердил правильность содержимого этих файлов:
![Config file transforms](https://i.stack.imgur.com/1GmOC.png)
Когда я создаю свою сборку релиза, у меня проверяются параметры Transform XML :
![XML Transformations checkbox in Azure DevOps](https://i.stack.imgur.com/TqXKU.png)
И когда я проверяю журнал сборки, похоже, что все преобразуется, как ожидалось:
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).
Однако , когда я проверяю файл LegendMainasted.exe.config в своей службе приложений, он показывает значения выпуска, а не промежуточные значения.
Следует отметить одну интересную вещь: сам файл app.config выглядит преобразованным как ожидается (он использует конфигурацию Staging). Я, вероятно, мог бы обойти это, как-то переименовав этот файл, но я не понимаю, почему он не работает как есть, тем более, что журналы Azure DevOps, похоже, указывают на это.
Также обратите внимание, что это Процесс отлично работает для нашей задачи развертывания веб-сайта, проблема возникает только в консольном проекте / веб-задании.
Что мне не хватает? Есть ли способ устранить неполадки в процессе веб-развертывания в Azure DevOps? Или есть лучший способ сделать это?
EDIT: вот мои конфигурации из артефактов, которые я загрузил из выходных данных сборки (значения цензурированы, так как они в основном все чувствительны):
LegendMain maintenance.exe.config
<?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>
LegendMain maintenance.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>
LegendMain maintenance.exe.Стадия .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>