|
The following target maybe
of use to you. <target name="fixCssReferences"> <foreach item="File"
property="filename"> <in> <items> <include
name="**/*.css"/> </items> </in> <do> <echo
message="${filename}"/> <property
name="cssFileName" value="${filename}"/> <property
name="find1" value="/vor/vor.site/"/> <property
name="replace1" value="/volvooceanrace/"/> <property
name="find2" value="/vor/vor.cms/"/> <property
name="replace2" value="/vorcms/"/> <script
language="C#"> <imports> <import
namespace="System.Text.RegularExpressions"/> <import
namespace="System.IO"/> </imports> <code><![CDATA[ public
static void ScriptMain(Project project) { StreamReader
reader = File.OpenText(project.Properties["cssFileName"]);//${filename}); string
file = String.Empty; try
{ Regex
expression1 = new Regex(project.Properties["find1"]); Regex
expression2 = new Regex(project.Properties["find2"]); file
= reader.ReadToEnd(); file
= expression1.Replace(file, project.Properties["replace1"]); file
= expression2.Replace(file, project.Properties["replace2"]); }
finally { //
must remember to close the file or the compile may not work reader.Close(); } //
create a writer and open the file TextWriter
tw = new StreamWriter(project.Properties["cssFileName"]);//${filename}); try
{ //
write a line of text to the file tw.WriteLine(file); }
finally { //
close the stream tw.Close(); } } ]]></code> </script> </do> </foreach> </target> From: I don’t see any type of functionality in nant or
nantcontrib to find and replace a string value in a file. There is xmlpoke for xml files. How are people doing the
same type of thing for non xml files? I wrote a task for this myself a while back, but sometimes
clients prefer to use only publicly supported tasks. It went something like this: <regex-replace file=”filepath”
find=”regex _expression_” replace=”replace value”
casesensitive=”true” /> Am I missing something that exists in nant or contrib
itself? Why wouldn’t something like this be included? Thanks, steve
_____________________________________________________________________ VirusChecked for Huntsworth plc _____________________________________________________________________ |
- [Nant-users] regex replace Steve Baker
- Re: [Nant-users] regex replace Ashley Moran
- RE: [Nant-users] regex replace Paul Cowan
- RE: [Nant-users] regex replace Steve Baker
- FW: [Nant-users] regex replace Steve Baker
- Re: FW: [Nant-users] regex replace Gary Feldman
- RE: [Nant-users] regex replace Robert Smith
- RE: FW: [Nant-users] regex replace Steve Baker
- RE: FW: [Nant-users] regex replace Craig Ducharme
- RE: FW: [Nant-users] regex replace Steve Baker
- Re: FW: [Nant-users] regex replace Edmund Schweppe
- RE: [Nant-users] regex replace Evan Levy
