Question: I want to set `VersionSuffix` from `Build.Sourcebranch` but this fails since `SourceBranch` contains `refs/heads/<branchname>`.

```
- task: DotNetCoreCLI@2
  condition: succeeded()
  inputs: 
    command: 'pack'
    versioningScheme: ByPrereleaseNumber
    majorVersion: '0' 
    minorVersion: '1' 
    patchVersion: '1' 
    packTimezone: 'utc' 
    buildProperties: VersionSuffix=$(Build.SourceBranch)-$(Build.BuildNumber)

```

I just want to add `.Replace('/','_')` and a few similar statements to `$(Build.SourceBranch)`, but I can't find anything in the expression syntax on how to do that.

It didn't work to send in another string (i.e. `VersionSuffixRaw`) and create the `VersionSuffix` with `String.Replace` inside the .csproj; it just got ignored for some reason. 

**Note**: There is `Build.SourceBranchName` which has the last part of a branchname, so if `SourceBranch` is `refs/heads/feature/foo`, `SourceBranchName` will be `foo`. However a branch namd `feature/JIRA-123_foo_unittest` will not work since \_ is not valid in a version string.

Answer: 
For others finding this through searches, there is now a replace expression: [MS Doc](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#replace)

Roughly like this to replace underscores with hypens:

```
variables:      
  suffix: $[replace(variables['build.sourcebranchname'], '_', '-')]

```
As @4c74356b41 pointed out. You can try adding powershell scripts to replace the Build.SourceBranch in your yaml build definition. And output the new sourcebranch to a new variable. Then you can use the new variable in the next steps. 

Below is just a simple example. [Click here](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch) for more information 

1, replace "/" to "\_" for SourceBranch and set the replaced value to variable newSourceBranch

```
- powershell: |
    $newbranch = "$(Build.SourceBranch)" -replace "/", "_"  
    echo "##vso[task.setvariable variable=newSourceBranch;isOutput=true]$newbranch"
  name: branchsetter 

```

2, Use the newSourceBranch in the following steps.

```
- powershell: |
    write-host "$(branchsetter.newSourceBranch)"

```