diff --git a/build/Microsoft.DotNet.Cli.Prepare.targets b/build/Microsoft.DotNet.Cli.Prepare.targets
index 5730f7979..a55a0da7f 100644
--- a/build/Microsoft.DotNet.Cli.Prepare.targets
+++ b/build/Microsoft.DotNet.Cli.Prepare.targets
@@ -9,7 +9,7 @@
-
+
@@ -213,10 +213,10 @@
Inputs="@(ZipTemplatesInput)"
Outputs="@(ZipTemplatesOutput)">
-
+
-
\ No newline at end of file
+
diff --git a/build/Microsoft.DotNet.Cli.Publish.targets b/build/Microsoft.DotNet.Cli.Publish.targets
index 0ac2783a7..653a3b223 100644
--- a/build/Microsoft.DotNet.Cli.Publish.targets
+++ b/build/Microsoft.DotNet.Cli.Publish.targets
@@ -16,10 +16,10 @@
FinishBuild" />
-
@@ -40,7 +40,7 @@
$(STORAGE_KEY)
$(STORAGE_ACCOUNT)
https://$(CloudDropAccountName).blob.core.windows.net/$(ContainerName)
-
+
@@ -51,10 +51,10 @@
- $(Product)/$(NugetVersion)/$([System.String]::Copy('%(Filename)%(Extension)').Replace('\' ,'/'))
+ $(Product)/$(NugetVersion)/$([System.String]::Copy('%(Filename)%(Extension)').Replace('\' ,'/'))
-
+
diff --git a/build/package/Microsoft.DotNet.Cli.Archive.targets b/build/package/Microsoft.DotNet.Cli.Archive.targets
index bd8a78d59..51fa11f4e 100644
--- a/build/package/Microsoft.DotNet.Cli.Archive.targets
+++ b/build/package/Microsoft.DotNet.Cli.Archive.targets
@@ -1,16 +1,44 @@
-
-
-
+
+
+
+
+
+
+ $(ArchiveOutputDirectory)/%(GenerateArchivesInputsOutputs.OutFileName)$(ArchiveExtension)
+
+
+
+
+
+
+
+
+
+
+
+
+
$(PackagesDirectory)
-
-
%(LayoutDefinition.OutputFiles)
$(ArchiveOutputDirectory)/%(LayoutDefinition.NameWithVersion)$(ArchiveExtension)
@@ -20,20 +48,8 @@
-
-
-
-
-
-
-
+
+
diff --git a/build_projects/dotnet-cli-build/ArchiveDirectory.cs b/build_projects/dotnet-cli-build/ArchiveDirectory.cs
deleted file mode 100644
index 7c8f95e15..000000000
--- a/build_projects/dotnet-cli-build/ArchiveDirectory.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) .NET Foundation and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System.IO;
-using System.IO.Compression;
-using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
-using Microsoft.DotNet.Cli.Build.Framework;
-using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
-
-namespace Microsoft.DotNet.Cli.Build
-{
- public class ArchiveDirectory : Task
- {
- [Required]
- public string FileName { get; set; }
-
- [Required]
- public string OutputDirectory { get; set; }
-
- [Required]
- public string InputDirectory { get; set; }
-
- public bool ForceZipArchive { get; set; }
-
- [Output]
- public string OutputArchive { get; set; }
-
- public override bool Execute()
- {
- if (!Directory.Exists(InputDirectory))
- {
- return true;
- }
-
- if (CurrentPlatform.IsPlatform(BuildPlatform.Windows) || ForceZipArchive)
- {
- OutputArchive = GenerateZip();
- }
- else
- {
- OutputArchive = GenerateTarGz();
- }
-
- Log.LogMessage($"Created Archive '{OutputArchive}'");
-
- return true;
- }
-
- public string GenerateZip()
- {
- var extension = ".zip";
- var outFile = Path.Combine(OutputDirectory, FileName + extension);
-
- CreateZipFromDirectory(InputDirectory, outFile);
-
- return outFile;
- }
-
- public string GenerateTarGz()
- {
- var extension = ".tar.gz";
- var outFile = Path.Combine(OutputDirectory, FileName + extension);
-
- CreateTarGzFromDirectory(InputDirectory, outFile);
-
- return outFile;
- }
-
- private static void CreateZipFromDirectory(string directory, string outputArchivePath)
- {
- FS.Mkdirp(Path.GetDirectoryName(outputArchivePath));
-
- if (File.Exists(outputArchivePath))
- {
- File.Delete(outputArchivePath);
- }
-
- ZipFile.CreateFromDirectory(directory, outputArchivePath, CompressionLevel.Optimal, false);
- }
-
- private static void CreateTarGzFromDirectory(string directory, string outputArchivePath)
- {
- FS.Mkdirp(Path.GetDirectoryName(outputArchivePath));
-
- if (File.Exists(outputArchivePath))
- {
- File.Delete(outputArchivePath);
- }
-
- Cmd("tar", "-czf", outputArchivePath, "-C", directory, ".")
- .Execute()
- .EnsureSuccessful();
- }
- }
-}
diff --git a/build_projects/dotnet-cli-build/TarGzFileCreateFromDirectory.cs b/build_projects/dotnet-cli-build/TarGzFileCreateFromDirectory.cs
new file mode 100644
index 000000000..5dfdb71a6
--- /dev/null
+++ b/build_projects/dotnet-cli-build/TarGzFileCreateFromDirectory.cs
@@ -0,0 +1,143 @@
+// 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 System;
+using System.IO;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace Microsoft.DotNet.Build.Tasks
+{
+ public sealed class TarGzFileCreateFromDirectory : ToolTask
+ {
+ ///
+ /// The path to the directory to be archived.
+ ///
+ [Required]
+ public string SourceDirectory { get; set; }
+
+ ///
+ /// The path of the archive to be created.
+ ///
+ [Required]
+ public string DestinationArchive { get; set; }
+
+ ///
+ /// Indicates if the destination archive should be overwritten if it already exists.
+ ///
+ public bool OverwriteDestination { get; set; }
+
+ ///
+ /// If zipping an entire folder without exclusion patterns, whether to include the folder in the archive.
+ ///
+ public bool IncludeBaseDirectory { get; set; }
+
+ ///
+ /// An item group of regular expressions for content to exclude from the archive.
+ ///
+ public ITaskItem[] ExcludePatterns { get; set; }
+
+ protected override bool ValidateParameters()
+ {
+ base.ValidateParameters();
+
+ var retVal = true;
+
+ if (File.Exists(DestinationArchive))
+ {
+ if (OverwriteDestination == true)
+ {
+ Log.LogMessage(MessageImportance.Low, $"{DestinationArchive} will be overwritten");
+ }
+ else
+ {
+ Log.LogError($"'{DestinationArchive}' already exists. Did you forget to set '{nameof(OverwriteDestination)}' to true?");
+
+ retVal = false;
+ }
+ }
+
+ SourceDirectory = Path.GetFullPath(SourceDirectory);
+
+ SourceDirectory = SourceDirectory.EndsWith(Path.DirectorySeparatorChar.ToString())
+ ? SourceDirectory
+ : SourceDirectory + Path.DirectorySeparatorChar;
+
+ if (!Directory.Exists(SourceDirectory))
+ {
+ Log.LogError($"SourceDirectory '{SourceDirectory} does not exist.");
+
+ retVal = false;
+ }
+
+ return retVal;
+ }
+
+ public override bool Execute()
+ {
+ return base.Execute();
+ }
+
+ protected override string ToolName
+ {
+ get { return "tar"; }
+ }
+
+ protected override MessageImportance StandardOutputLoggingImportance
+ {
+ get { return MessageImportance.High; } // or else the output doesn't get logged by default
+ }
+
+ protected override string GenerateFullPathToTool()
+ {
+ return "tar";
+ }
+
+ protected override string GenerateCommandLineCommands()
+ {
+ return $"{GetDestinationArchive()} {GetSourceSpecification()}";
+ }
+
+ private string GetSourceSpecification()
+ {
+ if (IncludeBaseDirectory)
+ {
+ var parentDirectory = Directory.GetParent(SourceDirectory).Parent.FullName;
+
+ var sourceDirectoryName = Path.GetFileName(Path.GetDirectoryName(SourceDirectory));
+
+ return $"--directory {parentDirectory} {sourceDirectoryName} {GetExcludes()}";
+ }
+ else
+ {
+ return $"--directory {SourceDirectory} {GetExcludes()} \".\"";
+ }
+ }
+
+ private string GetDestinationArchive()
+ {
+ return $"-czf {DestinationArchive}";
+ }
+
+ private string GetExcludes()
+ {
+ var excludes = String.Empty;
+
+ if (ExcludePatterns != null)
+ {
+ foreach (var excludeTaskItem in ExcludePatterns)
+ {
+ excludes += $" --exclude {excludeTaskItem.ItemSpec}";
+ }
+ }
+
+ return excludes;
+ }
+
+ protected override void LogToolCommand(string message)
+ {
+ base.LogToolCommand($"{base.GetWorkingDirectory()}> {message}");
+ }
+ }
+}