-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#4 v1.0.7; 支持install参数-ctn, 安装时自动复制xml到nuget缓存同名包的文件夹中
- Loading branch information
1 parent
e6ded26
commit d1b6433
Showing
18 changed files
with
316 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
src/IntelliSenseLocalizer.Core/Models/IntelliSenseFileDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
namespace IntelliSenseLocalizer.Models; | ||
using System.Globalization; | ||
|
||
public record class IntelliSenseFileDescriptor(ApplicationPackRefDescriptor OwnerPackRef, string Name, string FileName, string FilePath); | ||
namespace IntelliSenseLocalizer.Models; | ||
|
||
public record class IntelliSenseFileDescriptor(string Name, string FileName, string FilePath, string PackName, string Moniker, CultureInfo? Culture); |
26 changes: 26 additions & 0 deletions
26
src/IntelliSenseLocalizer.Core/Nuget/GlobalPackagesFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace IntelliSenseLocalizer.Nuget; | ||
|
||
public static class GlobalPackagesFinder | ||
{ | ||
public static readonly string Location; | ||
|
||
static GlobalPackagesFinder() | ||
{ | ||
//see https://learn.microsoft.com/zh-cn/nuget/consume-packages/managing-the-global-packages-and-cache-folders | ||
Location = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); | ||
} | ||
|
||
public static IEnumerable<NugetGlobalPackageDescriptor> EnumeratePackages() | ||
{ | ||
if (!Directory.Exists(Location)) | ||
{ | ||
yield break; | ||
} | ||
foreach (var packageFolder in Directory.EnumerateDirectories(Location, "*", SearchOption.TopDirectoryOnly)) | ||
{ | ||
var normalizedName = Path.GetFileName(packageFolder); | ||
|
||
yield return new NugetGlobalPackageDescriptor(normalizedName, packageFolder); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/IntelliSenseLocalizer.Core/Nuget/NugetGlobalPackageDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using IntelliSenseLocalizer.Utils; | ||
|
||
namespace IntelliSenseLocalizer.Nuget; | ||
|
||
public class NugetGlobalPackageDescriptor | ||
{ | ||
public string NormalizedName { get; set; } | ||
|
||
public string RootPath { get; set; } | ||
|
||
/// <summary> | ||
/// 应用程序包版本描述列表 | ||
/// </summary> | ||
public IReadOnlyList<NugetGlobalPackageVersionDescriptor> Versions => _versions ??= new List<NugetGlobalPackageVersionDescriptor>(EnumerateNugetGlobalPackageVersions(this)); | ||
|
||
private IReadOnlyList<NugetGlobalPackageVersionDescriptor>? _versions; | ||
|
||
public NugetGlobalPackageDescriptor(string normalizedName, string rootPath) | ||
{ | ||
if (string.IsNullOrWhiteSpace(normalizedName)) | ||
{ | ||
throw new ArgumentException($"“{nameof(normalizedName)}”不能为 null 或空白。", nameof(normalizedName)); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(rootPath)) | ||
{ | ||
throw new ArgumentException($"“{nameof(rootPath)}”不能为 null 或空白。", nameof(rootPath)); | ||
} | ||
|
||
NormalizedName = normalizedName; | ||
RootPath = rootPath; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{NormalizedName}"; | ||
} | ||
|
||
public static IEnumerable<NugetGlobalPackageVersionDescriptor> EnumerateNugetGlobalPackageVersions(NugetGlobalPackageDescriptor nugetGlobalPackage) | ||
{ | ||
var path = nugetGlobalPackage.RootPath; | ||
if (!Directory.Exists(path)) | ||
{ | ||
yield break; | ||
} | ||
|
||
//loop for path like %userprofile%\.nuget\packages\*\* | ||
foreach (var versionPath in Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly)) | ||
{ | ||
if (VersionUtil.TryParse(Path.GetFileName(versionPath), out var version)) | ||
{ | ||
yield return new NugetGlobalPackageVersionDescriptor(nugetGlobalPackage, version, versionPath); | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/IntelliSenseLocalizer.Core/Nuget/NugetGlobalPackageVersionDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace IntelliSenseLocalizer.Nuget; | ||
|
||
public class NugetGlobalPackageVersionDescriptor | ||
{ | ||
public NugetGlobalPackageVersionDescriptor(NugetGlobalPackageDescriptor ownerPackage, Version version, string rootPath) | ||
{ | ||
OwnerPackage = ownerPackage; | ||
Version = version; | ||
RootPath = rootPath; | ||
} | ||
|
||
public NugetGlobalPackageDescriptor OwnerPackage { get; } | ||
|
||
public Version Version { get; } | ||
|
||
public string RootPath { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"{Version}"; | ||
} | ||
|
||
public IReadOnlyList<NugetGlobalPackageVersionMonikerDescriptor> Monikers => _versions ??= new List<NugetGlobalPackageVersionMonikerDescriptor>(EnumerateNugetGlobalPackageVersionMonikers(this)); | ||
|
||
private IReadOnlyList<NugetGlobalPackageVersionMonikerDescriptor>? _versions; | ||
|
||
public static IEnumerable<NugetGlobalPackageVersionMonikerDescriptor> EnumerateNugetGlobalPackageVersionMonikers(NugetGlobalPackageVersionDescriptor nugetGlobalPackageVersion) | ||
{ | ||
var path = Path.Combine(nugetGlobalPackageVersion.RootPath, "lib"); | ||
if (!Directory.Exists(path)) | ||
{ | ||
yield break; | ||
} | ||
|
||
//loop for path like %userprofile%\.nuget\packages\xxx\1.0.0\lib\* | ||
foreach (var monikerPath in Directory.EnumerateDirectories(path, "*", SearchOption.TopDirectoryOnly)) | ||
{ | ||
yield return new NugetGlobalPackageVersionMonikerDescriptor(nugetGlobalPackageVersion, Path.GetFileName(monikerPath), monikerPath); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/IntelliSenseLocalizer.Core/Nuget/NugetGlobalPackageVersionMonikerDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using IntelliSenseLocalizer.Models; | ||
|
||
namespace IntelliSenseLocalizer.Nuget; | ||
|
||
public class NugetGlobalPackageVersionMonikerDescriptor | ||
{ | ||
/// <summary> | ||
/// .net 名称 | ||
/// </summary> | ||
public string Moniker { get; } | ||
|
||
public NugetGlobalPackageVersionDescriptor OwnerVersion { get; } | ||
|
||
/// <summary> | ||
/// 根目录 | ||
/// </summary> | ||
public string RootPath { get; } | ||
|
||
public IReadOnlyList<IntelliSenseFileDescriptor> IntelliSenseFiles => _intelliSenseFiles ??= new List<IntelliSenseFileDescriptor>(EnumerateIntelliSenseFiles(this)); | ||
|
||
private IReadOnlyList<IntelliSenseFileDescriptor>? _intelliSenseFiles; | ||
|
||
public NugetGlobalPackageVersionMonikerDescriptor(NugetGlobalPackageVersionDescriptor ownerVersion, string moniker, string rootPath) | ||
{ | ||
if (string.IsNullOrWhiteSpace(moniker)) | ||
{ | ||
throw new ArgumentException($"“{nameof(moniker)}”不能为 null 或空白。", nameof(moniker)); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(rootPath)) | ||
{ | ||
throw new ArgumentException($"“{nameof(rootPath)}”不能为 null 或空白。", nameof(rootPath)); | ||
} | ||
|
||
OwnerVersion = ownerVersion; | ||
RootPath = rootPath; | ||
Moniker = moniker; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{Moniker}"; | ||
} | ||
|
||
public static IEnumerable<IntelliSenseFileDescriptor> EnumerateIntelliSenseFiles(NugetGlobalPackageVersionMonikerDescriptor nugetGlobalPackageVersionMoniker) | ||
{ | ||
var path = nugetGlobalPackageVersionMoniker.RootPath; | ||
if (!Directory.Exists(path)) | ||
{ | ||
yield break; | ||
} | ||
|
||
foreach (var dllPath in Directory.EnumerateFiles(path, "*.dll", SearchOption.TopDirectoryOnly)) | ||
{ | ||
var xmlPath = Path.ChangeExtension(dllPath, ".xml"); | ||
if (File.Exists(xmlPath)) | ||
{ | ||
yield return new IntelliSenseFileDescriptor(Path.GetFileNameWithoutExtension(xmlPath), Path.GetFileName(xmlPath), xmlPath, nugetGlobalPackageVersionMoniker.OwnerVersion.OwnerPackage.NormalizedName, nugetGlobalPackageVersionMoniker.Moniker, null); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace IntelliSenseLocalizer.Utils; | ||
|
||
internal static class VersionUtil | ||
{ | ||
public static bool TryParse(string versionString, [NotNullWhen(true)] out Version? version) | ||
{ | ||
var index = versionString.IndexOf('-'); | ||
if (index >= 0) | ||
{ | ||
versionString = versionString[..index]; | ||
} | ||
if (Version.TryParse(versionString, out version)) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.