From dbf7a7aeb9169e34d32a0634a2ecca0d0ce06fc0 Mon Sep 17 00:00:00 2001 From: jun_lin Date: Thu, 9 Apr 2020 16:39:20 +0800 Subject: [PATCH 1/2] support Packages options for only copy specific package --- .../NugetContentRestoreTask.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs b/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs index 9a6cb1f..ec38564 100755 --- a/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs +++ b/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs @@ -1,16 +1,14 @@ -using System.Collections.Generic; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using MSBuild.NugetContentRestore.Tasks.Entities; +using MSBuild.NugetContentRestore.Tasks.Extensions; +using MSBuild.NugetContentRestore.Tasks.Utilities; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Xml.Serialization; -using MSBuild.NugetContentRestore.Tasks.Entities; -using MSBuild.NugetContentRestore.Tasks.Extensions; -using MSBuild.NugetContentRestore.Tasks.Utilities; - -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; - namespace MSBuild.NugetContentRestore.Tasks { public class NugetContentRestoreTask : Task @@ -32,6 +30,8 @@ public class NugetContentRestoreTask : Task public string[] AdditionalFolders { get; set; } public string[] AdditionalIgnoreFilePatterns { get; set; } + public string[] SpecificPackages { get; set; } + [Required] public string SolutionDir { get; set; } @@ -53,7 +53,7 @@ public string ConfigFileFullPath { return _configFileFullPath ?? Path.Combine(ProjectDir, "packages.config"); } - set { _configFileFullPath = value; } + set { _configFileFullPath = value; } } #endregion @@ -70,6 +70,7 @@ public override bool Execute() Log.LogMessage(MessageImportance.Low, "NugetContentRestore :: ProjectDir='{0}'", ProjectDir); Log.LogMessage(MessageImportance.Low, "NugetContentRestore :: ConfigFileFullPath='{0}'", ConfigFileFullPath); Log.LogMessage(MessageImportance.Low, "NugetContentRestore :: EnableSmartRestore='{0}'", EnableSmartRestore.ToString()); + Log.LogMessage(MessageImportance.Low, "NugetContentRestore :: SpecificPackages='{0}'", SpecificPackages); // Get NuGet Package Configuration var packages = GetPackages(); @@ -83,6 +84,11 @@ public override bool Execute() Log.LogMessage(MessageImportance.Low, "NugetContentRestore :: {0} :: ContentsFullPath='{1}'", package.FolderName, packageContentsFullPath); if (!Directory.Exists(packageContentsFullPath)) continue; + if (SpecificPackages != null) + { + if (!SpecificPackages.Contains(package.Name)) continue; + } + // Create Regex List for Ignore File Patterns var ignoreFilePatternsArray = _ignoreFilePatterns; if (AdditionalIgnoreFilePatterns != null) @@ -109,7 +115,7 @@ public override bool Execute() var sourceFolderInfo = new DirectoryInfo(Path.Combine(packageContentsFullPath, folder)); if (!sourceFolderInfo.Exists) continue; - Log.LogMessage(MessageImportance.High, "NugetContentRestore :: {0} :: {1} :: Restoring content files", package.FolderName, folder); + Log.LogMessage(MessageImportance.High, "NugetContentRestore :: {0} :: {1} :: Restoring content files", package.FolderName, folder); sourceFolderInfo.CopyTo(Path.Combine(ProjectDir, folder), true, filePatterns.ToArray(), EnableSmartRestore); } } From 8782b47f5f04d1e8619e82e579f617ba6c82c588 Mon Sep 17 00:00:00 2001 From: jun_lin Date: Wed, 20 Oct 2021 17:12:22 +0800 Subject: [PATCH 2/2] Issue: check AdditionalFolders is empty array --- MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs b/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs index ec38564..8b189e7 100755 --- a/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs +++ b/MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs @@ -109,7 +109,7 @@ public override bool Execute() } // Restore Package Content for additional folders (AdditionalFolder) - if (AdditionalFolders == null) continue; + if (AdditionalFolders == null || AdditionalFolders.Count() == 0) continue; foreach (var folder in AdditionalFolders) { var sourceFolderInfo = new DirectoryInfo(Path.Combine(packageContentsFullPath, folder));