Set <ApplicationDisplayVersion> using Target BeforeBuild in csproj

Simon Says 1 Reputation point
2022-09-01T02:46:58.273+00:00

Before project builds, I would like to read from external source and set the <ApplicationDisplayVersion>. In my csproj, I've the following:

   ...  
   <Target Name="CalculateVersionCodeProperties" BeforeTargets="Build">  
     
       <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">  
           <ApplicationDisplayVersion>1.2.3</ApplicationDisplayVersion>  
           <ApplicationVersion>2</ApplicationVersion>  
       </PropertyGroup>  
   </Target>  
   ...  

But the above doesn't seems to work. When running AppInfo.VersionString in the code, it is showing the default 1.0.0; it should read 1.2.3

Any pointers? Thanks.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,922 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,250 questions
{count} votes