|
|
|
@ -12,29 +12,39 @@ public static class AbpPackageMetadataHelper |
|
|
|
public static AbpPackageMetadata? GetMetaData(Assembly assembly) |
|
|
|
{ |
|
|
|
var assemblyPath = assembly.Location; |
|
|
|
try |
|
|
|
{ |
|
|
|
if (string.IsNullOrWhiteSpace(assemblyPath)) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(assemblyPath)) |
|
|
|
return null; |
|
|
|
var dir = Path.GetDirectoryName(assemblyPath); |
|
|
|
if (dir == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
var dir = Path.GetDirectoryName(assemblyPath); |
|
|
|
if (dir == null) |
|
|
|
return null; |
|
|
|
var abppkgPath = FindFileUpwards(dir, "*.abppkg"); |
|
|
|
if (abppkgPath == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
var abppkgPath = Directory.GetFiles(dir, "*.abppkg").FirstOrDefault(); |
|
|
|
if (abppkgPath == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
var metadata = ReadOrCreateMetadata(abppkgPath); |
|
|
|
|
|
|
|
var abpslnPath = FindFileUpwards(dir, "*.abpsln"); |
|
|
|
if (!string.IsNullOrEmpty(abpslnPath)) |
|
|
|
{ |
|
|
|
metadata.AbpSlnPath = abpslnPath; |
|
|
|
} |
|
|
|
|
|
|
|
var metadata = ReadOrCreateMetadata(abppkgPath); |
|
|
|
var abpslnPath = FindAbpSlnFile(dir); |
|
|
|
if (!abpslnPath.IsNullOrEmpty()) |
|
|
|
return metadata; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
metadata.AbpSlnPath = abpslnPath; |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return metadata; |
|
|
|
} |
|
|
|
|
|
|
|
private static AbpPackageMetadata ReadOrCreateMetadata(string path) |
|
|
|
@ -44,10 +54,9 @@ public static class AbpPackageMetadataHelper |
|
|
|
|
|
|
|
var metadata = new AbpPackageMetadata(); |
|
|
|
|
|
|
|
if (doc.TryGetValue("projectId", out var existingProjectId) && existingProjectId is string id && |
|
|
|
!string.IsNullOrWhiteSpace(id)) |
|
|
|
if (doc.TryGetValue("projectId", out var existingProjectId) && existingProjectId.ToString() != null) |
|
|
|
{ |
|
|
|
metadata.ProjectId = id; |
|
|
|
metadata.ProjectId = existingProjectId.ToString()!; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -55,29 +64,27 @@ public static class AbpPackageMetadataHelper |
|
|
|
doc["projectId"] = metadata.ProjectId; |
|
|
|
} |
|
|
|
|
|
|
|
// Role
|
|
|
|
if (doc.TryGetValue("role", out var existingRole) && existingRole is string role) |
|
|
|
if (doc.TryGetValue("role", out var existingRole) && existingRole.ToString() != null) |
|
|
|
{ |
|
|
|
metadata.Role = role; |
|
|
|
metadata.Role = existingRole.ToString()!; |
|
|
|
} |
|
|
|
|
|
|
|
// Save if new ProjectId was generated
|
|
|
|
var updatedJson = JsonSerializer.Serialize(doc, new JsonSerializerOptions {WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase}); |
|
|
|
var updatedJson = JsonSerializer.Serialize(doc, new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); |
|
|
|
File.WriteAllText(path, updatedJson); |
|
|
|
|
|
|
|
return metadata; |
|
|
|
} |
|
|
|
|
|
|
|
private static string? FindAbpSlnFile(string startingDir) |
|
|
|
|
|
|
|
private static string? FindFileUpwards(string startingDir, string searchPattern) |
|
|
|
{ |
|
|
|
var currentDir = new DirectoryInfo(startingDir); |
|
|
|
|
|
|
|
while (currentDir != null) |
|
|
|
{ |
|
|
|
var abpslnFile = currentDir.GetFiles("*.abpsln").FirstOrDefault(); |
|
|
|
if (abpslnFile != null) |
|
|
|
var file = currentDir.GetFiles(searchPattern).FirstOrDefault(); |
|
|
|
if (file != null) |
|
|
|
{ |
|
|
|
return abpslnFile.FullName; |
|
|
|
return file.FullName; |
|
|
|
} |
|
|
|
|
|
|
|
currentDir = currentDir.Parent; |
|
|
|
|