I have the following Wix project. In post build event I would like to use the target path, which is modified in BeforeBuild
target. The modification is to create msi filename with assembly version. However, in post build event target is not modified yet and the value is based on OutputName
only.
<Project>
<Import Project="Sdk.props" Sdk="WixToolset.Sdk" Version="4.0.2" />
<PropertyGroup>
<OutputName>Server</OutputName>
<Name>ServerInstaller</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DefineConstants>Debug</DefineConstants>
<SuppressIces>ICE61;ICE57</SuppressIces>
<BindFiles>false</BindFiles>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\userve\userve.csproj">
<Name>userve</Name>
<Project>{b20b1c16-7dfd-40f4-a0cb-6b7bb227d10f}</Project>
<Private>True</Private>
<DoNotHarvest>True</DoNotHarvest>
<RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
<RefTargetDir>INSTALLFOLDER</RefTargetDir>
</ProjectReference>
</ItemGroup>
<Import Project="Sdk.targets" Sdk="WixToolset.Sdk" Version="4.0.2" />
<Target Name="BeforeBuild">
<GetAssemblyIdentity AssemblyFiles="$(SolutionDir)Control\bin\$(Configuration)\Control.dll">
<Output ItemName="AssemblyInfo" TaskParameter="Assemblies" />
</GetAssemblyIdentity>
<CreateProperty Value="$(OutputName).%(AssemblyInfo.Version)">
<Output PropertyName="TargetName" TaskParameter="Value" />
</CreateProperty>
<CreateProperty Value="$(TargetName)$(TargetExt)">
<Output PropertyName="TargetFileName" TaskParameter="Value" />
</CreateProperty>
<CreateProperty Value="$(TargetDir)$(TargetFileName)">
<Output PropertyName="TargetPath" TaskParameter="Value" />
</CreateProperty>
</Target>
<PropertyGroup>
<PostBuildEvent>echo $(TargetPath)</PostBuildEvent>
</PropertyGroup>
</Project>
How to get modified TargetPath
in post build event?
From my understanding,the issue may be caused by two reasons. One is that the target BeforeBuild
is not run. Another is Common macros for MSBuild commands and properties override issue.
1.You can specify a post build event from Project menu->click {ProjectName} Properties->Select Build > Events->Post-build Event. Visual Studio modifies your project file by adding the PostBuild
target and the necessary MSBuild code to execute the steps you provided.
example:
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Message Text="$(TargetPath)" Importance="high" />
</Target>
Then build the project and watch the value of $(TargetPath)
and see if it has been modified.
2.Rename the TargetPath
to TargetPath_customize
(different name from commonly used macros).
<CreateProperty Value="$(TargetDir)$(TargetFileName)">
<Output PropertyName="TargetPath_customize" TaskParameter="Value" />
</CreateProperty>
Docs Referred:
Hope it can help you.