Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 2.14 KB

getfilehash-task.md

File metadata and controls

64 lines (52 loc) · 2.14 KB
title ms.date ms.topic dev_langs helpviewer_keywords author ms.author manager ms.workload
GetFileHash Task | Microsoft Docs
01/28/2019
reference
VB
CSharp
C++
jsharp
GetFileHash task [MSBuild]
MSBuild, GetFileHash task
ghogen
ghogen
jillfra
multiple

GetFileHash task

Computes checksums of the contents of a file or set of files.

This task was added in 15.8, but requires a workaround to use for MSBuild versions below 16.0.

Task parameters

The following table describes the parameters of the GetFileHash task.

Parameter Description
Files Required xref:Microsoft.Build.Framework.ITaskItem[] parameter.

The files to be hashed.
Items xref:Microsoft.Build.Framework.ITaskItem[] output parameter.

The Files input with additional metadata set to the file hash.
Hash String output parameter.

The hash of the file. This output is only set if there was exactly one item passed in.
Algorithm Optional String parameter.

The algorithm. Allowed values: SHA256, SHA384, SHA512. Default = SHA256.
MetadataName Optional String parameter.

The metadata name where the hash is stored in each item. Defaults to FileHash.
HashEncoding Optional String parameter.

The encoding to use for generated hashes. Defaults to hex. Allowed values = hex, base64.

Example

The following example uses the GetFileHash task to determine and print the checksum of the FilesToHash items.

<Project>
  <ItemGroup>
    <FilesToHash Include="$(MSBuildThisFileDirectory)\*" />
  </ItemGroup>
  <Target Name="GetHash">
    <GetFileHash Files="@(FilesToHash)">
      <Output
          TaskParameter="Items"
          ItemName="FilesWithHashes" />
    </GetFileHash>

    <Message Importance="High"
             Text="@(FilesWithHashes->'%(Identity): %(FileHash)')" />
  </Target>
</Project>

See also