VerifyFileHash task

Verifies that a file matches the expected file hash.

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 VerifyFileHash task.

Parameter Description
File Required ITaskItem parameter.

The files to be hashed and validated.
Hash Required String parameter.

The expected hash of the file.
Items ITaskItem[] output parameter.

The Files input with additional metadata set to the file hash.
Algorithm Optional String parameter.

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

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


The following example uses the VerifyFileHash task to verify its own checksum.

  <Target Name="VerifyHash">
    <GetFileHash Files="$(MSBuildProjectFullPath)">
          ItemName="FilesWithHashes" />

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

    <VerifyFileHash File="$(MSBuildThisFileFullPath)"
                    Hash="$(ExpectedHash)" />

See also