Skip to content

Commit 58c0423

Browse files
committed
Reworked embedded resource enumeration
When enumerating manifest resource names with Linq, Mono throws `InvalidProgramExceptions`. See https://travis-ci.org/asbjornu/GitVersion/builds/132266378#L7579 for details on the failure. Doing a simple `foreach` and `yield return` seems to solve the problem.
1 parent cb2fa33 commit 58c0423

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
namespace GitVersion.VersionAssemblyInfoResources
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.IO;
56
using System.Linq;
67
using GitVersionCore.Extensions;
78

89
public class AssemblyVersionInfoTemplates
910
{
10-
static IDictionary<string, FileInfo> assemblyInfoSourceList;
11+
static readonly IDictionary<string, FileInfo> assemblyInfoSourceList;
1112

1213
static AssemblyVersionInfoTemplates()
1314
{
14-
var enclosingNamespace = typeof(AssemblyVersionInfoTemplates).Namespace;
15-
16-
var files = typeof(AssemblyVersionInfoTemplates)
17-
.Assembly
18-
.GetManifestResourceNames()
19-
.Where(n => n.StartsWith(enclosingNamespace ?? string.Empty)).Select(f => new FileInfo(f));
20-
21-
assemblyInfoSourceList = files.ToDictionary(k => k.Extension, v => v);
15+
assemblyInfoSourceList = GetEmbeddedVersionAssemblyFiles().ToDictionary(k => k.Extension, v => v);
2216
}
2317

2418
public static string GetAssemblyInfoTemplateFor(string assemblyInfoFile)
@@ -34,5 +28,19 @@ public static string GetAssemblyInfoTemplateFor(string assemblyInfoFile)
3428
}
3529
return null;
3630
}
31+
32+
private static IEnumerable<FileInfo> GetEmbeddedVersionAssemblyFiles()
33+
{
34+
var enclosingNamespace = typeof(AssemblyVersionInfoTemplates).Namespace;
35+
36+
if (enclosingNamespace == null)
37+
throw new InvalidOperationException("The AssemblyVersionInfoTemplates class is missing its namespace.");
38+
39+
foreach (var name in typeof(AssemblyVersionInfoTemplates).Assembly.GetManifestResourceNames())
40+
{
41+
if (name.StartsWith(enclosingNamespace))
42+
yield return new FileInfo(name);
43+
}
44+
}
3745
}
3846
}

0 commit comments

Comments
 (0)