Skip to content

Commit 0f09cef

Browse files
committed
Render content files metadata too
This is very useful for contentFiles which might provide buildAction, copyToOutput and Flatten metadata too.
1 parent e5a7239 commit 0f09cef

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/dotnet-nugetize/Program.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int Execute(bool binlog, bool debug)
5353
var foundPackage = false;
5454

5555
foreach (var metadata in items.Root.Descendants("PackageMetadata")
56-
.Distinct(AnonymousEqualityComparer.Create<XElement>(
56+
.Distinct(AnonymousComparer.Create<XElement>(
5757
(x, y) => x.Element("PackageId")?.Value == y.Element("PackageId")?.Value,
5858
x => x.Element("PackageId")?.Value.GetHashCode() ?? 0)))
5959
{
@@ -102,12 +102,12 @@ static int Execute(bool binlog, bool debug)
102102
.Where(x =>
103103
x.Element("PackagePath") != null &&
104104
x.Element("PackageId")?.Value == packageId)
105-
.Select(x => x.Element("PackagePath").Value)
106-
.Distinct()
107-
.OrderBy(x => Path.GetDirectoryName(x))
108-
.ThenBy(x => x);
105+
//.Select(x => x.Element("PackagePath").Value)
106+
.Distinct(AnonymousComparer.Create<XElement>(x => x.Element("PackagePath").Value))
107+
.OrderBy(x => Path.GetDirectoryName(x.Element("PackagePath").Value))
108+
.ThenBy(x => x.Element("PackagePath").Value);
109109

110-
RenderContents(contents.ToList(), 0, 0, "");
110+
Render(contents.ToList(), 0, 0, "");
111111
Console.WriteLine();
112112
}
113113

@@ -123,12 +123,12 @@ static int Execute(bool binlog, bool debug)
123123
return 0;
124124
}
125125

126-
static int RenderContents(IList<string> files, int index, int level, string path)
126+
static int Render(IList<XElement> files, int index, int level, string path)
127127
{
128128
while (index < files.Count)
129-
130129
{
131-
var file = files[index];
130+
var element = files[index];
131+
var file = element.Element("PackagePath").Value;
132132
var dir = Path.GetDirectoryName(file);
133133
var paths = dir.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
134134

@@ -143,15 +143,28 @@ static int RenderContents(IList<string> files, int index, int level, string path
143143
ColorConsole.Write("/".Gray());
144144

145145
ColorConsole.WriteLine(paths[level].Green(), "/".Gray());
146-
index = RenderContents(files, index, level + 1, string.Join(Path.DirectorySeparatorChar, paths[..(level + 1)]));
146+
index = Render(files, index, level + 1, string.Join(Path.DirectorySeparatorChar, paths[..(level + 1)]));
147147
}
148148
else
149149
{
150150
Console.Write(new string(' ', (level + 1) * 2 + 2));
151151
if (level == 0)
152152
ColorConsole.Write("/".Gray());
153153

154-
ColorConsole.WriteLine(Path.GetFileName(file).White());
154+
var attributes = new List<string>();
155+
if (element.Element("BuildAction")?.Value is string buildAction)
156+
attributes.Add("buildAction=" + buildAction);
157+
if (element.Element("CopyToOutput")?.Value is string copyToOutput)
158+
attributes.Add("copyToOutput=" + copyToOutput);
159+
if (element.Element("Flatten")?.Value is string flatten)
160+
attributes.Add("flatten=" + flatten);
161+
162+
ColorConsole.Write(Path.GetFileName(file).White());
163+
if (attributes.Count > 0)
164+
ColorConsole.Write((" (" + string.Join(',', attributes) + ")").Gray());
165+
166+
Console.WriteLine();
167+
155168
index++;
156169
}
157170
}
@@ -183,10 +196,13 @@ static bool Execute(string program, string arguments, bool debug = false)
183196
return proc.ExitCode == 0;
184197
}
185198

186-
static class AnonymousEqualityComparer
199+
static class AnonymousComparer
187200
{
188201
public static IEqualityComparer<T> Create<T>(Func<T, T, bool> equals, Func<T, int> getHashCode)
189202
=> new AnonymousEqualityComparer<T>(equals, getHashCode);
203+
204+
public static IEqualityComparer<T> Create<T>(Func<T, object> value)
205+
=> new AnonymousEqualityComparer<T>((x, y) => Equals(value(x), value(y)), x => value(x).GetHashCode());
190206
}
191207

192208
class AnonymousEqualityComparer<T> : IEqualityComparer<T>

0 commit comments

Comments
 (0)