OverviewThis 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 :
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. PrerequisitesThis extension supports Azure DevOps Server 2019 and Azure Devops Online. How To UseAfter 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 locationThe Search location is a parmater that can be set. The default value is $(Build.SourcesDirectory). Replace In Files Between TextOnce you've added the 'Replace In Files Between Text' you should have the following: Once you've added the task to your Build pipeline you need to configure your individual task. Inside your task conifguration you have 6 settings that are imporant:
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 TextAs 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 TextAs 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 TextAs 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 SearchThis 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 PatternThis 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 FilesThis 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 Replace In Files Text By TextOnce you've added the 'Replace In Files Text By Text' you should have the following: Once you've added the task to your Build pipeline you need to configure your individual task. Inside your task conifguration you have 5 settings that are imporant:
Azure Devops Variables can be used in all those fields. Search For TextSearch 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 TextReplace 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 SearchThis 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 PatternThis 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 FilesThis 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. TargetThe goal of this add-in is to replace text in source files before building. Version HistoryVersion 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. |