MSBuild download file task

I had a need to download a file in MSBuild and didn’t want to assume any tools on the server. I coded together a simple task which lets you specify the URL to download, and optionally a file name or/and a output path. The goal was to keep it as small as possible, thus the bad formatting and non existent error checking.

<DownloadFile Url=””  />
<DownloadFile Url=”” OutputFolder=”D:\” File=”awesome.txt” />

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="">
   <UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
      <Url ParameterType="System.String" Required="true" />
      <File ParameterType="System.String" Required="false" />
      <OutputFolder ParameterType="System.String" Required="false" />
      <Using Namespace="System.Web"/>
      <Code Type="Fragment" Language="cs"><![CDATA[
        using (var client = new System.Net.WebClient())
            { client.DownloadFile(Url, (OutputFolder != null ? OutputFolder + "/" : "") + (File ?? System.IO.Path.GetFileName(new Uri(Url).LocalPath))); }