NAnt 0.86, script task with RegEx and RegularExpressions

less than 1 minute read,


Muah.  While updating to NAnt 0.86, I was stuck with the following error while trying to execute a <script> task:

The name ‘Regex’ does not exist in the current context

I was using a <script> task to do some RegEx some files apart of the build process.  Well, turns out that NAnt 0.86-beta2 has a breaking changeSystem.Text.RegularExpressions is now removed by default from the imported assemblies of <script> tasks.  Oh well…

The following should get you back on track:

641     <script language="C#">
642           <code>
643 <![CDATA[
644         //C# code goes here...
645   ]]>
646           </code>
647         <imports>
648             <import namespace="System.Text.RegularExpressions"/>
649         </imports>
650         <references>
651             <include name="System.dll"/>
652         </references>
653     </script>

Just add the <imports> and <references> section to the <script> task and all should be well again! :)

Brian Chavez




Leave a comment

Your email address will not be published. Required fields are marked *