Merge pull request #6993 from mmitche/generate-checksums-using-new-arcade-task
Generate checksums using new arcade task
This commit is contained in:
commit
30b2fc31c2
3 changed files with 1 additions and 68 deletions
|
@ -1,66 +0,0 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Microsoft.DotNet.Build.Tasks
|
||||
{
|
||||
public class GenerateChecksums : Task
|
||||
{
|
||||
/// <summary>
|
||||
/// An item collection of files for which to generate checksums. Each item must have metadata
|
||||
/// 'DestinationPath' that specifies the path of the checksum file to create.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public ITaskItem[] Items { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
foreach (ITaskItem item in Items)
|
||||
{
|
||||
try
|
||||
{
|
||||
string destinationPath = item.GetMetadata("DestinationPath");
|
||||
if (string.IsNullOrEmpty(destinationPath))
|
||||
{
|
||||
throw new Exception($"Metadata 'DestinationPath' is missing for item '{item.ItemSpec}'.");
|
||||
}
|
||||
|
||||
if (!File.Exists(item.ItemSpec))
|
||||
{
|
||||
throw new Exception($"The file '{item.ItemSpec}' does not exist.");
|
||||
}
|
||||
|
||||
Log.LogMessage(
|
||||
MessageImportance.High,
|
||||
"Generating checksum for '{0}' into '{1}'...",
|
||||
item.ItemSpec,
|
||||
destinationPath);
|
||||
|
||||
using (FileStream stream = File.OpenRead(item.ItemSpec))
|
||||
{
|
||||
HashAlgorithm hashAlgorithm = SHA512.Create();
|
||||
byte[] hash = hashAlgorithm.ComputeHash(stream);
|
||||
string checksum = BitConverter.ToString(hash).Replace("-", string.Empty);
|
||||
File.WriteAllText(destinationPath, checksum);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// We have 2 log calls because we want a nice error message but we also want to capture the
|
||||
// callstack in the log.
|
||||
Log.LogError("An exception occurred while trying to generate a checksum for '{0}'.", item.ItemSpec);
|
||||
Log.LogMessage(MessageImportance.Low, e.ToString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,6 @@
|
|||
<UsingTask TaskName="AddMetadataIsPE" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
<UsingTask TaskName="Crossgen" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
<UsingTask TaskName="CopyBlobsToLatest" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
<UsingTask TaskName="GenerateChecksums" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
<UsingTask TaskName="GetRuntimePackRids" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
<UsingTask TaskName="GenerateMSBuildExtensionsSWR" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
<UsingTask TaskName="GetLinuxNativeInstallerDependencyVersions" AssemblyFile="$(CoreSdkTaskDll)"/>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name="GenerateChecksums"
|
||||
<Target Name="GenerateArtifactChecksums"
|
||||
DependsOnTargets="InitializeChecksumItemGroup;"
|
||||
AfterTargets="GenerateInstallers"
|
||||
Inputs="@(ArtifactsForGeneratingChecksums)"
|
||||
|
|
Loading…
Reference in a new issue