I have a Msbuild target that gets executed successfully by adding a single key called 'ProjectID' to the appsetting section of web.config. Now am changing the behavior of this target by adding one more key 'ApplicationId' to the same appsetting section. The log shows the xmlpoke is executed for both. But only the projectID value is correctly replaced with every run.
(Excerpt from)PropertyGroup definition:
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="15.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Needs to be set! -->
<ProjectID>4424cc12-4368-45ad-ad5b-19e821eb91d4</ProjectID>
</PropertyGroup>
TargetCode:
<Target Name="UpdateConfigFilesInSolutionDir">
<ItemGroup>
<WebConfigFilesSolutionDir Include="$(SolutionDir)\**\*.config" />
</ItemGroup>
<Message Text="WebConfigFilesPath: %(WebConfigFilesSolutionDir.FullPath)"
Importance="high"></Message>
<XmlPoke XmlInputPath="%(WebConfigFilesSolutionDir.FullPath)"
Query="//appSettings/add[@key='ProjectID']/@value" Value="$(ProjectID)"
/>
<XmlPoke XmlInputPath="%(WebConfigFilesSolutionDir.FullPath)"
Query="//appSettings/add[@key='ApplicationId']/@value" Value="SetAValue"
/>
</Target>
Output log observed:
Using "XmlPoke" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 2019-06-25 08:37:13,202 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Task "XmlPoke" 2019-06-25 08:37:13,203 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Replaced "value" with "4424cc12-4368-45ad-ad5b-19e821eb91d4". 2019-06-25 08:37:13,203 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Made 1 replacement(s). 2019-06-25 08:37:13,204 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Done executing task "XmlPoke". 2019-06-25 08:37:13,204 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Task "XmlPoke" 2019-06-25 08:37:13,204 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Made 0 replacement(s). 2019-06-25 08:37:13,204 [9] DEBUG EP.BuildService.Handlers.ProjectBuildLogger [2e0de09a-3fd8-4932-bc1d-e3a66dd3c1ca] - Done executing task "XmlPoke".
What I have tried so far:
- Originally was passing ApplicationId value in PropertyGroup. It didn't help.
- So hardcoding the value as seen in the code , Value="SetAValue" still not adding the key to appsetting.