Skip to content

Instantly share code, notes, and snippets.

@Serivy
Created September 13, 2016 05:03
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Serivy/cbf2bc3eedeecedcb5cffc2fe3e4206d to your computer and use it in GitHub Desktop.
MSBuild download task
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<Url ParameterType="System.String" Required="true" />
<File ParameterType="System.String" Required="false" />
<OutputFolder ParameterType="System.String" Required="false" />
</ParameterGroup>
<Task>
<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))); }
]]></Code>
</Task>
</UsingTask>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment