From 35ecd2fc123fc47499baa58428f5873acbe2f12c Mon Sep 17 00:00:00 2001 From: Damien Date: Wed, 4 Sep 2024 17:36:44 +0200 Subject: [PATCH] Fix install module csharp --- TopModel.Generator/Program.cs | 26 ++++++++++++++------ TopModel.Generator/TopModel.Generator.csproj | 4 +-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/TopModel.Generator/Program.cs b/TopModel.Generator/Program.cs index 592f9a6a..42b5f991 100644 --- a/TopModel.Generator/Program.cs +++ b/TopModel.Generator/Program.cs @@ -382,18 +382,30 @@ void HandleFile(FileInfo file) using var packageReader = new PackageArchiveReader(packageStream); var nuspecReader = await packageReader.GetNuspecReaderAsync(ct); - File.WriteAllText( - Path.Combine(moduleFolder, "min-version"), - nuspecReader.GetDependencyGroups() - .Single(dg => dg.TargetFramework.ToString() == framework) - .Packages - .Single(d => d.Id == "TopModel.Generator.Core").VersionRange.MinVersion!.ToString()); + var dependencies = nuspecReader.GetDependencyGroups() + .Single(dg => dg.TargetFramework.ToString() == framework) + .Packages; + + var minVersion = dependencies.Single(d => d.Id == "TopModel.Generator.Core").VersionRange.MinVersion!.ToString(); + + File.WriteAllText(Path.Combine(moduleFolder, "min-version"), minVersion); foreach (var file in packageReader.GetFiles().Where(f => f == $"lib/{framework}/{dep.FullName}.dll" || f.EndsWith("config.json"))) { packageReader.ExtractFile(file, Path.Combine(moduleFolder, file.Split('/').Last()), NullLogger.Instance); } + foreach (var otherDep in dependencies.Where(d => d.Id != "TopModel.Generator.Core")) + { + using var packageStreamDep = new MemoryStream(); + await nugetResource.CopyNupkgToStreamAsync(otherDep.Id, otherDep.VersionRange.MinVersion, packageStreamDep, nugetCache, NullLogger.Instance, ct); + using var packageReaderDep = new PackageArchiveReader(packageStreamDep); + foreach (var file in packageReaderDep.GetFiles().Where(f => f == $"lib/netstandard2.0/{otherDep.Id}.dll")) + { + packageReaderDep.ExtractFile(file, Path.Combine(moduleFolder, file.Split('/').Last()), NullLogger.Instance); + } + } + hasInstalled = true; logger.LogInformation($"({dep.ConfigKey}) Installation de {dep.FullName}@{dep.Version} terminée avec succès."); } @@ -413,7 +425,7 @@ void HandleFile(FileInfo file) continue; } - generators.AddRange(Assembly.LoadFrom(Path.Combine(moduleFolder, $"{dep.FullName}.dll")).GetExportedTypes().Where(t => GetIGenRegInterface(t) != null)); + generators.AddRange(Directory.GetFiles(moduleFolder, "*.dll").SelectMany(a => Assembly.LoadFrom(a).GetExportedTypes().Where(t => GetIGenRegInterface(t) != null))); resolvedConfigKeys.Add(dep.ConfigKey, dep.Version); } } diff --git a/TopModel.Generator/TopModel.Generator.csproj b/TopModel.Generator/TopModel.Generator.csproj index f13921a2..0e983fd9 100644 --- a/TopModel.Generator/TopModel.Generator.csproj +++ b/TopModel.Generator/TopModel.Generator.csproj @@ -1,7 +1,7 @@  - net6.0;net8.0 + net8.0;net6.0 12 Exe enable @@ -13,7 +13,7 @@ true ../.nupkg modgen - 2.0.0 + 2.0.1 false JabX;gideruette Générateur de modèle TopModel.