I'm trying to set the version suffix on my DLLs to Git commit id available on Azure DevOps via environmental variable Build_SourceVersion
. If that environmental variable is not available, the suffix should be set to random GUID. My Directory.Build.props
file looks like this:
<Project>
<PropertyGroup>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionSuffix Condition="'$(Test-Path env:Build_SourceVersion)' == 'True'">$((Get-Variable Build_SourceVersion).Substring(0, 7))</VersionSuffix>
<VersionSuffix Condition="'$(Test-Path env:Build_SourceVersion)' == 'False'">$([System.Guid]::NewGuid().ToString(N).ToLower().Substring(0, 7))</VersionSuffix>
</PropertyGroup>
</Project>
Though when I build my DLLs do not get any Product version set. What am I doing wrong here? If I try to set the <VersionSuffix>
to $([System.Guid]::NewGuid().ToString(N).ToLower().Substring(0, 7))
my DLLs are labeled with random GUID. If I try $((Get-Variable Build_SourceVersion).Substring(0, 7))
I don't get any errors at least but the combination seems not to be working.