title: Encode String to Base64 in MSBuild
body: <p>I want to convert a string to base64 within a msbuild target but msbuild tells me the type convert is not available.</p>
  
  <pre><code>&lt;ItemGroup&gt;
    &lt;Headers Include="Authorization"&gt;
      &lt;Content&gt;$([Convert]::ToBase64String(&amp;quot;user:password&amp;quot;))&lt;/Content&gt;
    &lt;/Headers&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>Can somone help me?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Found a solution I don't like:</p>
  
  <pre><code>&lt;UsingTask TaskName="ToBase64" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" &gt;
      &lt;ParameterGroup&gt;
        &lt;In ParameterType="System.String" Required="true" /&gt;
        &lt;Out ParameterType="System.String" Output="true" /&gt;
      &lt;/ParameterGroup&gt;
    &lt;Task&gt;
      &lt;Code Type="Fragment" Language="cs"&gt;
        Out = System.Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(In));
      &lt;/Code&gt;
    &lt;/Task&gt;
  &lt;/UsingTask&gt;
  
  &lt;Target Name="WebRequest"&gt;
    &lt;ToBase64 In="$(auth)"&gt;
      &lt;Output PropertyName="authBase64" TaskParameter="Out" /&gt;
    &lt;/ToBase64&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>Is there a better way?</p>