Skip to content

Commit 43ee330

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/visualstudio-docs-pr (branch live)
2 parents 790c961 + e3b9cbe commit 43ee330

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

docs/msbuild/verifyfilehash-task.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ms.workload:
1818
---
1919
# VerifyFileHash task
2020

21-
Verifies that a file matches the expected file hash.
21+
Verifies that a file matches the expected file hash. If the hash doesn't match, the task fails.
2222

2323
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.
2424

@@ -55,7 +55,31 @@ The following example uses the `VerifyFileHash` task to verify its own checksum.
5555
</Project>
5656
```
5757

58+
On MSBuild 16.5 and later, if you don't want the build to fail when the hash doesn't match, such as if you are using the hash comparison as a condition for control flow, you can downgrade the warning to a message using the following code:
59+
60+
```xml
61+
<PropertyGroup>
62+
<MSBuildWarningsAsMessages>$(MSBuildWarningsAsMessages);MSB3952</MSBuildWarningsAsMessages>
63+
</PropertyGroup>
64+
65+
<Target Name="DemoVerifyCheck">
66+
<VerifyFileHash File="$(MSBuildThisFileFullPath)"
67+
Hash="1"
68+
ContinueOnError="WarnAndContinue" />
69+
70+
<PropertyGroup>
71+
<HashMatched>$(MSBuildLastTaskResult)</HashMatched>
72+
</PropertyGroup>
73+
74+
<Message Condition=" '$(HashMatched)' != 'true'"
75+
Text="The hash didn't match" />
76+
77+
<Message Condition=" '$(HashMatched)' == 'true'"
78+
Text="The hash did match" />
79+
</Target>
80+
```
81+
5882
## See also
5983

6084
- [Tasks](../msbuild/msbuild-tasks.md)
61-
- [Task reference](../msbuild/msbuild-task-reference.md)
85+
- [Task reference](../msbuild/msbuild-task-reference.md)

0 commit comments

Comments
 (0)