In MSBuild, I am trying to dynamically generate a property, one that is dependent on the value of another property. This seems related to but not identical with How get exec task output with msbuild and Dynamically create a property in msbuild to be used in a calltarget subtarget
Please see the sample below. It is trying generate property WixVariable, which is dependent on property MsiVersion. (FYI, Though it is not really relevant to this problem, this code relates to preparing WixVariables, which is passed to wix.exe to generate a MS installer.)
At (1) property MsiVersion is assigned the value "unknown"
At (2) property WixVariables is assigned the value "MSI_VERSION=unknown;OTHER_VARIABLE=OtherValue"
At (3) a powershell script is run to generate the actual version number. To keep the sample simple, it just returns "4.3".
At (4) property MsiVersion is supposed to be assigned the new value "4.3"
And this should update property WixVariables to have the value "MSI_VERSION=4.3;OTHER_VARIABLE=OtherValue"
But that doesn't work. WixVariables remains unchanged.
I've been experimenting with this for several hours but cannot get the result I need: WixVariables to reflect the generated value of MsiVersion.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" InitialTargets="EnsureWixToolsetInstalled" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AProperty>SomeValue</AProperty>
(1) <MsiVersion>unknown</MsiVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
... snip
(2) <WixVariables>MSI_VERSION=$(MsiVersion);OTHER_VARIABLE=OtherValue</WixVariables>
</PropertyGroup>
<Target Name="BeforeBuild" />
(3) <Exec ConsoleToMSBuild="true" Command="powershell -NoProfile -ExecutionPolicy ByPass -Command " Write-Output 4.3 "">
(4) <Output TaskParameter="ConsoleOutput" PropertyName="MsiVersion" />
</Exec>
</Target>
</Project>