Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Never mind. I have written a custom task to do the job:</p> <pre><code> public class ReplaceExtension : Task { [Required] public string FilePath { get; set; } public string NewExtension { get; set; } [Output] public string Result { get; set; } public override bool Execute() { if (string.IsNullOrEmpty(FilePath)) { Log.LogError("FilePath cannot be empty!"); return false; } try { int length = FilePath.Length; int startIndex = length; int oldExtensionLength = 0; while (--startIndex &gt;= 0) { char ch = FilePath[startIndex]; if (ch == '.') { oldExtensionLength = length - startIndex; break; } if (ch == Path.DirectorySeparatorChar || ch == Path.AltDirectorySeparatorChar || ch == Path.VolumeSeparatorChar) { break; } } bool isNewExtensionEmpty = string.IsNullOrEmpty(NewExtension) || (NewExtension.Length == 1 &amp;&amp; NewExtension[0] == '.'); if (isNewExtensionEmpty) { // The new extension is empty - remove the old extension. if (oldExtensionLength &gt; 0) { Result = FilePath.Remove(startIndex, oldExtensionLength); } else { Result = FilePath; } } else { // Replace the old extension with the new one. StringBuilder sb = new StringBuilder(FilePath.Length - oldExtensionLength + NewExtension.Length + (NewExtension[0] == '.' ? 0 : 1)); sb.Append(FilePath, 0, FilePath.Length - oldExtensionLength); if (NewExtension[0] != '.') { sb.Append('.'); } sb.Append(NewExtension); Result = sb.ToString(); } } catch (Exception ex) { Log.LogErrorFromException(ex); } return !Log.HasLoggedErrors; } } </code></pre> <p>I am using it like this:</p> <pre><code> &lt;Target Name="CreateProperties"&gt; &lt;ReplaceExtension FilePath="$(TestResultsFilePath)" NewExtension="xml"&gt; &lt;Output TaskParameter="Result" PropertyName="NUnitResultsFilePath"/&gt; &lt;/ReplaceExtension&gt; &lt;/Target&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload