'How do I get the current Publish Profile name within a msbuild task?

I am trying to get the name of the publish profile being used for the publish so I can log it.

I've tried $(PublishProfile) and $(PublishProfileName) based on some other threads posted on here but those variables always return empty.

I'm running on VS 2019 and have modified the .csproj file but using the VS publish via Web Deploy. The code below works great just need to capture the selected Profile name somehow.

Here is the name I'm looking to get:

enter image description here

Here is an example of my code:

<Target Name="PublishHistoryInsert" AfterTargets="Publish">
<XmlRead XPath="//*[@name='ConnectionString']/@connectionString" XmlFileName="Web.config">
    <Output TaskParameter="Value" PropertyName="MyConnectionString" />
</XmlRead>

<SqlExecute ConnectionString="$(MyConnectionString)" Command="insert into PublishHistory ([Environment],Project,PublishedBy,PublishedOn,Profile) Values ('$(Environment)','Internal App','$(UserName)','$(TodayDate) $(TodayTime)','$(PublishProfile)')" />


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source