Skip to content
| Marketplace
Sign in
Azure DevOps>Azure Pipelines>Replace Text in Source Files
Replace Text in Source Files

Replace Text in Source Files

Samayas

samayas.eu
|
3,597 installs
| (5) | Free
Allows you to replace a text between start and end into files based, or to replace a value with another value, in the source directory.
Get it free

Overview

This extension contains a 2 build tasks that will replace data in source files before they are being build. These tasks allow to replace a text in a source file with another text.

There are 2 Tasks :

  • Replace in File Between Text.
  • Replace in File Text By Text.

Sometimes there might be a need to replace a version number or public key or some other value that has been pre checked into a source file that is not easily replaced by other means before the build does happen.

Prerequisites

This extension supports Azure DevOps Server 2019 and Azure Devops Online.

How To Use

After installing the extension, you can add 2 tasks name 'Replace In Files Bewteen Text' and 'Replace In Files Text By Text' to a new or existing build definition.

Search location

The Search location is a parmater that can be set. The default value is $(Build.SourcesDirectory).

Replace In Files Between Text

Once you've added the 'Replace In Files Between Text' you should have the following:

add-task

Once you've added the task to your Build pipeline you need to configure your individual task.

configure-task

Inside your task conifguration you have 6 settings that are imporant:

  • Search Start of Text
  • Search End of Text
  • Replace With Text
  • Choose the Type of Search
  • Files Search Pattern
  • List of Files

By filling in all the settings your task will look for a specific start string and end string and replace a value between those.

Azure Devops Variables can be used in all those fields.

Search Start of Text

As the description says you're looking in each line of the source code for a text starting with what is entered here.

Sample Line -> [assembly: AssemblyInformationalVersion("1.1.1.1")]

So if you enter 'AssemblyInformationalVersion("' it will look for a line containing that text and stopping just at the end before the version 1.1.1.1.

Search End of Text

As the description says the task is looking for the 'End of Text' but only on the lines where the Start of Text already found a result.

Sample Line -> [assembly: AssemblyInformationalVersion("1.1.1.1")]

So if you enter '")]' it will look for the position just at the end of version 1.1.1.1.

Replace With Text

As the description says, the task will replace the value found between 'Start of Text' and 'End of Text'.

Sample Line -> [assembly: AssemblyInformationalVersion("1.1.1.1")]

So if you enter a new version number '2.2.2.2-CI-Build213' the new line will look as follows

New Line -> [assembly: AssemblyInformationalVersion("2.2.2.2-CI-Build213")]

Advanced Choose the Type of Search

This radio button allows you to make a choice between the types of searches the task will use.

You have the choice to either search for a Pattern or search in a list of files.

Advanced Files Search Pattern

This contains by default *.cs, and will look through the source directory in your project for all files that match the pattern that you specify.

You can also specify a more specific name b*.cs.

If the search criteria is to wide you can always use a more specific list of files.

Advanced List of Files

This can containt a list of files in which the task should look. The files list only needs to contain a relative path to the source file.

Should the List of Files be to long then you can always try a pattern.

The entry should always start with \

The format of the list of files should be as follows : \directory...\file.cs \directory...\file.config \directory\file.cs \file.config

list-files

Replace In Files Text By Text

Once you've added the 'Replace In Files Text By Text' you should have the following:

add-task

Once you've added the task to your Build pipeline you need to configure your individual task.

configure-task

Inside your task conifguration you have 5 settings that are imporant:

  • Search For Text
  • Replace With Text
  • Choose the Type of Search
  • Files Search Pattern
  • List of Files

Azure Devops Variables can be used in all those fields.

Search For Text

Search For Text will be looking for a specific Text in a line.

Sample Line -> [assembly: Version("1.1.1.1")]

So if you enter '1.1.1.1' it will be replaced with a new value.

Replace With Text

Replace With Text Will replace the value found and enter a new value.

Sample Line -> [assembly: Version("1.1.1.1")]

So if you enter '2.2.2.2-CI-Build213' it replaced value '1.1.1.1'.

New Line -> [assembly: AssemblyInformationalVersion("2.2.2.2-CI-Build213")]

Advanced Choose the Type of Search

This radio button allows you to make a choice between the types of searches the task will use.

You have the choice to either search for a Pattern or search in a list of files.

Advanced Files Search Pattern

This contains by default *.cs, and will look through the source directory in your project for all files that match the pattern that you specify.

You can also specify a more specific name b*.cs.

If the search criteria is to wide you can always use a more specific list of files.

Advanced List of Files

This can containt a list of files in which the task should look. The files list only needs to contain a relative path to the source file.

Should the List of Files be to long then you can always try a pattern.

Target

The goal of this add-in is to replace text in source files before building.

Version History

Version 1.0 Initial Version

Version 1.1 Release to Public

Version 2.0 Update depreciated task execution handler to Powershell3. Add Search parameter. Version 2.1 Fixed labeling output. Make Replace With Text non required. Version 2.2 New logo

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft