Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions docs/msbuild/getfilehash-task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: "GetFileHash Task | Microsoft Docs"
ms.date: "01/28/2019"
ms.topic: "reference"
f1_keywords:
- "http://schemas.microsoft.com/developer/msbuild/2003#GetFileHash"
dev_langs:
- "VB"
- "CSharp"
- "C++"
- "jsharp"
helpviewer_keywords:
- "GetFileHash task [MSBuild]"
- "MSBuild, GetFileHash task"
ms.assetid: ???
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mikejo5000 should I just create a new GUID for these, or is there something else I could do to help? In general I was guessing on a lot of this metadata.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rainersigwald ms.assetid is used only for topics migrated from MSDN, so please remove that. Everything else looks good except f1_keywords. This metadata item is for F1 links from the IDE (if an F1 link exists) formatted like this example: vc.task.xdcmake
If there's no plan to link to the topic from the IDE, just remove f1_keywords.
Thanks!

author: mikejo5000
ms.author: mikejo
manager: jillfra
ms.workload:
- "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](https://github.com/Microsoft/msbuild/pull/3999#issuecomment-458193272) 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.<br /><br />The files to be hashed.|
|`Items`|<xref:Microsoft.Build.Framework.ITaskItem>`[]` output parameter.<br /><br />The `Files` input with additional metadata set to the file hash.|
|`Hash`|`String` output parameter.<br /><br />The hash of the file. This is only set if there was exactly one item passed in.|
|`Algorithm`|Optional `String` parameter.<br /><br />The algorithm. Allowed values: `SHA256`, `SHA384`, `SHA512`. Default = `SHA256`.|
|`MetadataName`|Optional `String` parameter.<br /><br />The metadata name where the hash is stored in each item. Defaults to `FileHash`.|
|`HashEncoding`|Optional `String` parameter.<br /><br />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.

```xml
<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

[Tasks](../msbuild/msbuild-tasks.md)

[Task reference](../msbuild/msbuild-task-reference.md)
8 changes: 7 additions & 1 deletion docs/msbuild/msbuild-task-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ Tasks provide the code that runs during the build process. The tasks in the foll
[GetAssemblyIdentity task](../msbuild/getassemblyidentity-task.md)
Retrieves the assembly identities from the specified files and outputs the identity information.

[GetFrameworkPath task](../msbuild/getframeworkpath-task.md)
[GetFileHash task](../msbuild/getfilehash-task.md)
Computes checksums of the contents of a file or set of files.

[GetFrameworkPath task](../msbuild/getframeworkpath-task.md)
Retrieves the path to the [!INCLUDE[dnprdnshort](../code-quality/includes/dnprdnshort_md.md)] assemblies.

[GetFrameworkSdkPath task](../msbuild/getframeworksdkpath-task.md)
Expand Down Expand Up @@ -205,6 +208,9 @@ Tasks provide the code that runs during the build process. The tasks in the foll
[Vbc task](../msbuild/vbc-task.md)
Invokes the Visual Basic compiler to produce executables, dynamic-link libraries, or code modules..

[VerifyFileHash task](../msbuild/verifyfilehash-task.md)
Verifies that a file matches the expected file hash.

[Warning task](../msbuild/warning-task.md)
Logs a warning during a build based on an evaluated conditional statement.

Expand Down
66 changes: 66 additions & 0 deletions docs/msbuild/verifyfilehash-task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: "VerifyFileHash Task | Microsoft Docs"
ms.date: "01/28/2019"
ms.topic: "reference"
f1_keywords:
- "http://schemas.microsoft.com/developer/msbuild/2003#VerifyFileHash"
dev_langs:
- "VB"
- "CSharp"
- "C++"
- "jsharp"
helpviewer_keywords:
- "VerifyFileHash task [MSBuild]"
- "MSBuild, VerifyFileHash task"
ms.assetid: ???
author: mikejo5000
ms.author: mikejo
manager: jillfra
ms.workload:
- "multiple"
---
# VerifyFileHash task

Verifies that a file matches the expected file hash.

This task was added in 15.8, but requires a [workaround](https://github.com/Microsoft/msbuild/pull/3999#issuecomment-458193272) to use for MSBuild versions below 16.0.

## Task parameters

The following table describes the parameters of the `VerifyFileHash` task.

|Parameter|Description|
|---------------|-----------------|
|`File`|Required <xref:Microsoft.Build.Framework.ITaskItem> parameter.<br /><br />The files to be hashed and validated.|
|`Hash`|Required `String` parameter.<br /><br />The expected hash of the file.|
|`Items`|<xref:Microsoft.Build.Framework.ITaskItem>`[]` output parameter.<br /><br />The `Files` input with additional metadata set to the file hash.|
|`Algorithm`|Optional `String` parameter.<br /><br />The algorithm. Allowed values: `SHA256`, `SHA384`, `SHA512`. Default = `SHA256`.|
|`HashEncoding`|Optional `String` parameter.<br /><br />The encoding to use for generated hashes. Defaults to `hex`. Allowed values = `hex`, `base64`.|

## Example

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

```xml
<Project>
<Target Name="VerifyHash">
<GetFileHash Files="$(MSBuildProjectFullPath)">
<Output
TaskParameter="Items"
ItemName="FilesWithHashes" />
</GetFileHash>

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

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

## See also

[Tasks](../msbuild/msbuild-tasks.md)

[Task reference](../msbuild/msbuild-task-reference.md)