Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support SpecificPackages options #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions MSBuild.NugetContentRestore.Tasks/NugetContentRestoreTask.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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; }

Expand All @@ -53,7 +53,7 @@ public string ConfigFileFullPath
{
return _configFileFullPath ?? Path.Combine(ProjectDir, "packages.config");
}
set { _configFileFullPath = value; }
set { _configFileFullPath = value; }
}

#endregion
Expand All @@ -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();
Expand All @@ -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)
Expand All @@ -103,13 +109,13 @@ 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));
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);
}
}
Expand Down