1
+ using System . Diagnostics . CodeAnalysis ;
1
2
using System . Text . RegularExpressions ;
2
3
using static System . IO . File ;
3
4
@@ -31,10 +32,7 @@ Task("test")
31
32
32
33
Task ( "version" )
33
34
. Description ( "Updates the version number in the sources." )
34
- . DoesForEach ( GetFiles ( "*/*.csproj" ) , file => {
35
- var pattern = new Regex ( @"<Version>\d+(\.\d+){2}</Version>" ) ;
36
- WriteAllText ( file . FullPath , pattern . Replace ( ReadAllText ( file . FullPath ) , $ "<Version>{ version } </Version>") ) ;
37
- } ) ;
35
+ . DoesForEach ( GetFiles ( "*/*.csproj" ) , file => ReplaceInFile ( file , @"<Version>\d+(\.\d+){2}</Version>" , $ "<Version>{ version } </Version>") ) ;
38
36
39
37
Task ( "default" )
40
38
. Description ( "The default task." )
@@ -43,3 +41,14 @@ Task("default")
43
41
. IsDependentOn ( "build" ) ;
44
42
45
43
RunTarget ( target ) ;
44
+
45
+ /// <summary>
46
+ /// Replaces the specified pattern in a given file.
47
+ /// </summary>
48
+ /// <param name="file">The path of the file to be processed.</param>
49
+ /// <param name="pattern">The regular expression to find.</param>
50
+ /// <param name="replacement">The replacement text.</param>
51
+ /// <param name="options">The regular expression options to use.</param>
52
+ void ReplaceInFile ( FilePath file , [ StringSyntax ( StringSyntaxAttribute . Regex ) ] string pattern , string replacement , RegexOptions options = RegexOptions . None ) {
53
+ WriteAllText ( file . FullPath , Regex . Replace ( ReadAllText ( file . FullPath ) , pattern , replacement , options ) ) ;
54
+ }
0 commit comments