Fix .NET Framework build.

This commit is contained in:
Tom Deseyn 2023-06-09 11:42:50 +02:00
parent df78b1fe28
commit 8e20e9586e

View file

@ -2,6 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#if !NETFRAMEWORK
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,6 +13,7 @@ using System.IO.Enumeration;
using System.IO.MemoryMappedFiles; using System.IO.MemoryMappedFiles;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
#endif
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
@ -26,6 +30,13 @@ namespace Microsoft.DotNet.Build.Tasks
[Required] [Required]
public string Directory { get; set; } = ""; public string Directory { get; set; } = "";
#if NETFRAMEWORK
public override bool Execute()
{
Log.LogError($"{nameof(RemoveDuplicateFilesWithHardLinks)} is not supported on .NET Framework.");
return false;
}
#else
public override bool Execute() public override bool Execute()
{ {
if (OperatingSystem.IsWindows()) if (OperatingSystem.IsWindows())
@ -55,7 +66,7 @@ namespace Microsoft.DotNet.Build.Tasks
}; };
// Group them by file size. // Group them by file size.
IEnumerable<string[]> filesGroupedBySize = fse.GroupBy(file => file.Length, IEnumerable<string?[]> filesGroupedBySize = fse.GroupBy(file => file.Length,
file => file.FullName, file => file.FullName,
(size, files) => files.ToArray()); (size, files) => files.ToArray());
@ -64,14 +75,14 @@ namespace Microsoft.DotNet.Build.Tasks
{ {
for (int i = 0; i < files.Length; i++) for (int i = 0; i < files.Length; i++)
{ {
string path1 = files[i]; string? path1 = files[i];
if (path1 is null) if (path1 is null)
{ {
continue; // already linked. continue; // already linked.
} }
for (int j = i + 1; j < files.Length; j++) for (int j = i + 1; j < files.Length; j++)
{ {
string path2 = files[j]; string? path2 = files[j];
if (path2 is null) if (path2 is null)
{ {
continue; // already linked. continue; // already linked.
@ -155,5 +166,6 @@ namespace Microsoft.DotNet.Build.Tasks
// This native method is used by the runtime to create hard links. It is not exposed through a public .NET API. // This native method is used by the runtime to create hard links. It is not exposed through a public .NET API.
[DllImport("libSystem.Native", SetLastError = true)] [DllImport("libSystem.Native", SetLastError = true)]
static extern int SystemNative_Link(string source, string link); static extern int SystemNative_Link(string source, string link);
#endif
} }
} }