#azure-devops #azure-application-insights
#azure-devops #azure-application-insights
Вопрос:
В моем приложении .NET Framework мне нужно изменить аналитические данные приложения InstrumentationKey
ApplicationInsights.config
как часть сборки для разных сред (Dev, UAT и т. Д.).
В моем решении у меня есть ApplicationInsights.config
файл, который не содержит InstumentationKey
У меня также есть ApplicationInsights.Dev.config
файл преобразования следующим образом
<?xml version="1.0"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<InstrumentationKey>89c95f9d-0f89-41cb-938b-175499e3052a</InstrumentationKey>
</ApplicationInsights>
В моем конвейере YAML у меня есть следующий шаг:
- task: FileTransform@1
inputs:
folderPath: 'path/to/directory'
enableXmlTransform: true
xmlTransformationRules: '-transform ApplicationInsights.Dev.config -xml ApplicationInsights.config'
Задача сборки завершается, но когда я просматриваю результирующий ApplicationInsight.config
файл в рабочем каталоге InstrumentationKey
, его нет.
Может кто-нибудь увидеть, что я здесь делаю не так?
Комментарии:
1. Как насчет проблемы? Разрешен ли приведенный ниже ответ на ваш вопрос, если нет, не могли бы вы сообщить мне последнюю информацию об этой проблеме?
Ответ №1:
Если вы хотите заменить инструментирование, включите ApplicationInsight.Конфигурация должна быть:
<?xml version="1.0"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<InstrumentationKey>89c95f9d-0f89-41cb-938b-175499e3052a</InstrumentationKey>
</ApplicationInsights>
и ваша конфигурация преобразования ApplicationInsights.Dev.config
:
<?xml version="1.0"?>
<!-- For more information on using app.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<!-- In case configuration is not the root element, replace it with root element in source configuration file -->
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<InstrumentationKey xdt:Transform="Replace">
Value for dev
</InstrumentationKey>
</ApplicationInsights>
а затем для такого конвейера:
trigger: none
pr: none
pool:
vmImage: 'windows-latest'
steps:
- task: FileTransform@1
inputs:
folderPath: $(Build.SourcesDirectory)/stackoverflow/76-config-transform/
enableXmlTransform: true
xmlTransformationRules: '-transform ApplicationInsights.Dev.config -xml ApplicationInsights.config'
- bash: cat ApplicationInsights.config
workingDirectory: $(Build.SourcesDirectory)/stackoverflow/76-config-transform/
вы получите
Ответ №2:
Мне нужно изменить инструментальный ключ Application Insights в ApplicationInsights.config как часть сборки для разных сред
Чтобы преобразовать файл конфигурации XML, вам необходимо указать синтаксис атрибута transform в вашем ApplicationInsights.Dev.config
файле.
Поскольку ваш ApplicationInsights.config
файл, который не содержит InstumentationKey
, вы должны использовать атрибут transform Insert
, xdt:Transform="Insert"
:
<InstrumentationKey xdt:Transform="Insert">89c95f9d-0f89-41cb-938b-175499e3052a</InstrumentationKey>
Пожалуйста, проверьте синтаксис преобразования документа для получения более подробной информации.
ApplicationInsights.Dev.config
Должно быть:
<?xml version="1.0"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<InstrumentationKey xdt:Transform="Insert">89c95f9d-0f89-41cb-938b-175499e3052a</InstrumentationKey>
</ApplicationInsights>
Результат теста: