Compartilhar via


DownloadFile task

Downloads the specified files using the Hyper-Text Transfer Protocol (HTTP).

Note

The DownloadFile task is available in MSBuild 15.8 and above only.

Parameters

The following table describes the parameters of the DownloadFile task.

Parameter Description
DestinationFileName Optional ITaskItem parameter

The name to use for the downloaded file. By default, the file name is derived from the SourceUrl or the remote server.
DestinationFolder Required ITaskItem parameter.

Specifies the destination folder to download the file to. If folder is created if it does not exist.
DownloadedFile Optional ITaskItem output parameter.

Specifies the file that was downloaded.
Retries Optional Int32 parameter.

Specifies how many times to attempt to download, if all previous attempts have failed. Defaults to zero.
RetryDelayMilliseconds Optional Int32 parameter.

Specifies the delay in milliseconds between any necessary retries. Defaults to 5000.
SkipUnchangedFiles Optional Boolean parameter.

If true, skips the downloading of files that are unchanged. Defaults to true. The DownloadFile task considers files to be unchanged if they have the same size and the same last modified time according to the remote server.

Note: Not all HTTP servers indicate the last modified date of files will cause the file to be downloaded again.
SourceUrl Required String parameter.

Specifies the URL to download.

Remarks

In addition to the parameters listed above, this task inherits parameters from the TaskExtension class, which itself inherits from the Task class. For a list of these additional parameters and their descriptions, see TaskExtension base class.

Example

The following example downloads a file and includes it in the Content items prior to building the project.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
      <MyUrl>https://raw.githubusercontent.com/Microsoft/msbuild/master/LICENSE</MyUrl>
    </PropertyGroup>

    <Target Name="DownloadContentFiles" BeforeTargets="Build">
        <DownloadFile
            SourceUrl="$(MyUrl)"
            DestinationFolder="$(MSBuildProjectDirectory)">
        <Output TaskParameter="DownloadedFile" ItemName="Content" />
      </DownloadFile>
    </Target>

</Project>

See also