title: nant replace regex in file while preserving encoding
body: <p>I'm using a Nant build to update the dates in C# AssemblyInfo.cs files (lots of them).
  Each file contains a line like...</p>
  <pre><code>[assembly: AssemblyCopyright(&quot;Copyright Whoever 2020-2021&quot;)]
  </code></pre>
  <p>or</p>
  <pre><code>[assembly: AssemblyCopyright(&quot;Copyright Whoever 2021&quot;)]
  </code></pre>
  <p>and I'm updating that to say</p>
  <pre><code>[assembly: AssemblyCopyright(&quot;Copyright Whoever 2020-2022&quot;)]
  </code></pre>
  <p>or</p>
  <pre><code>[assembly: AssemblyCopyright(&quot;Copyright Whoever 2021-2022&quot;)]
  </code></pre>
  <p>I have a property <code>versionFilePath</code> which contains the name of the file, and I'm doing...</p>
  <pre><code>  &lt;loadfile file=&quot;${versionFilePath}&quot; property=&quot;versionFileContent&quot;/&gt;
    &lt;regex pattern=&quot;^(?'prefix'\[assembly:\s+AssemblyCopyright\(&amp;quot;.+?)(?'fromdate'\d\d\d\d)(?'todate'\-\d\d\d\d)?(?'suffix'.*&amp;quot;\)\])&quot; input=&quot;${versionFileContent}&quot; options=&quot;Multiline&quot; /&gt;
  
    &lt;loadfile file=&quot;${versionFilePath}&quot; property=&quot;versionFileContent&quot;&gt;
      &lt;filterchain&gt;
        &lt;replacestring from=&quot;${prefix}${fromdate}${todate}${suffix}&quot; to=&quot;${prefix}${fromdate}-${datetime::get-year(datetime::now())}${suffix}&quot; /&gt;
      &lt;/filterchain&gt;
    &lt;/loadfile&gt;
    &lt;echo file=&quot;${versionFilePath}&quot;&gt;${versionFileContent}&lt;/echo&gt;
  </code></pre>
  <p>And this is <em>basically</em> working, however the file that it is writing is a different encoding than the one which it loaded; and the version control system we're using doesn't like that very much.</p>
  <p>How can I make it do the replacement without altering the encoding? Can I capture the encoding when the file is being loaded so that I can use the same value when the file is being written? Or is there a better way of doing this, where I can just do the Regex replace directly on the file?</p>