From bf82785f87caeab8382f9854805bdf44f50044cf Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Wed, 19 Apr 2023 19:53:42 +0300 Subject: [PATCH] =?UTF-8?q?nuget=20-=20=D0=B8=D0=BD=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=D0=BB=D1=8F=D1=86=D0=B8=D1=8F=20=D1=81=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=20=D1=81=20=D1=83=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=BF=D0=BA=D0=B8=20netstandard2.0=20=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D1=8B=D1=85=20dll?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=BF=D0=B0=D0=BF=D0=BE=D0=BA=20runtimes\win?= =?UTF-8?q?-x64\native\?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VisualPascalABCNET/Projects/NuGetTasks.cs | 48 ++++++++++++++++---- VisualPascalABCNET/Projects/ProjectTasks.cs | 21 +++++++-- VisualPascalABCNET/Projects/ReferenceForm.cs | 21 ++++++--- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/VisualPascalABCNET/Projects/NuGetTasks.cs b/VisualPascalABCNET/Projects/NuGetTasks.cs index 8f8b67c14..74327f899 100644 --- a/VisualPascalABCNET/Projects/NuGetTasks.cs +++ b/VisualPascalABCNET/Projects/NuGetTasks.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace VisualPascalABC { - delegate void NugetPackageInstallHandler(bool result, string[] dlls, string[] xmls); + delegate void NugetPackageInstallHandler(bool result, string[] dlls, string[] xmls, string[] ndlls); delegate void NugetPackageOutputHandler(string output); class NuGetTasks @@ -26,28 +26,31 @@ namespace VisualPascalABC nugetProcess.StartInfo.FileName = Path.Combine(PascalABCCompiler.Tools.GetExecutablePath(), "nuget.exe"); nugetProcess.StartInfo.UseShellExecute = false; nugetProcess.StartInfo.Arguments = "install "+packageId+ " -NonInteractive"; - nugetProcess.StartInfo.CreateNoWindow = true; - nugetProcess.StartInfo.RedirectStandardOutput = true; - nugetProcess.StartInfo.RedirectStandardError = true; + nugetProcess.StartInfo.CreateNoWindow = false; + nugetProcess.StartInfo.RedirectStandardOutput = false; + nugetProcess.StartInfo.RedirectStandardError = false; nugetProcess.StartInfo.WorkingDirectory = dir; nugetProcess.EnableRaisingEvents = true; - nugetProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; + //nugetProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; nugetProcess.Exited += new EventHandler(delegate (object o, EventArgs a) { string[] dlls; string[] xmls; - bool result = getPackage(dir, out dlls, out xmls); - finishAction(result, dlls, xmls); + string[] ndlls; + bool result = getPackage(dir, out dlls, out xmls, out ndlls); + finishAction(result, dlls, xmls, ndlls); }); nugetProcess.Start(); nugetProcess.WaitForExit(); } - static bool getPackage(string workingDir, out string[] dlls, out string[] xmls) + static bool getPackage(string workingDir, out string[] dlls, out string[] xmls, out string[] ndlls) { dlls = null; xmls = null; + ndlls = null; List dllList = new List(); List xmlList = new List(); + List nativedllList = new List(); bool result = false; foreach (string dir in Directory.EnumerateDirectories(workingDir)) { @@ -59,6 +62,8 @@ namespace VisualPascalABC dotnetDir = Path.Combine(libDir, "net45"); if (!Directory.Exists(dotnetDir)) dotnetDir = Path.Combine(libDir, "net46"); + if (!Directory.Exists(dotnetDir)) + dotnetDir = Path.Combine(libDir, "netstandard2.0"); if (!Directory.Exists(dotnetDir)) dotnetDir = Path.Combine(libDir, "net"); if (!Directory.Exists(dotnetDir)) @@ -77,9 +82,36 @@ namespace VisualPascalABC } } } + // А теперь разбираемся с native dlls. Они находятся в папке runtimes\win-x64\nativeassets\такое же окончание как в dotnetdir + string runtimesDir = Path.Combine(dir, "runtimes", "win-x64", "nativeassets"); + if (!Directory.Exists(runtimesDir)) + runtimesDir = Path.Combine(dir, "runtimes", "win-x64", "native"); + if (Directory.Exists(runtimesDir)) + { + string dotnetDir = Path.Combine(runtimesDir, "net40"); + if (!Directory.Exists(dotnetDir)) + dotnetDir = Path.Combine(runtimesDir, "net45"); + if (!Directory.Exists(dotnetDir)) + dotnetDir = Path.Combine(runtimesDir, "net46"); + if (!Directory.Exists(dotnetDir)) + dotnetDir = Path.Combine(runtimesDir, "netstandard2.0"); + if (!Directory.Exists(dotnetDir)) + dotnetDir = Path.Combine(runtimesDir, "net"); + if (!Directory.Exists(dotnetDir)) + dotnetDir = runtimesDir; + if (Directory.Exists(dotnetDir)) + { + string[] nativedllFiles = Directory.GetFiles(dotnetDir, "*.dll"); + if (nativedllFiles.Length > 0) + { + nativedllList.AddRange(nativedllFiles); + } + } + } } dlls = dllList.ToArray(); xmls = xmlList.ToArray(); + ndlls = nativedllList.ToArray(); return result; } } diff --git a/VisualPascalABCNET/Projects/ProjectTasks.cs b/VisualPascalABCNET/Projects/ProjectTasks.cs index 4bf7ff361..e47b3f8b3 100644 --- a/VisualPascalABCNET/Projects/ProjectTasks.cs +++ b/VisualPascalABCNET/Projects/ProjectTasks.cs @@ -50,7 +50,8 @@ namespace VisualPascalABC else { string[] assemblies = ReferenceForm.Instance.GetSelectedFileAssemblies(); - List assm_lst = new List(); + string[] native_dlls = ReferenceForm.Instance.GetNativeDlls(); + List assm_lst = new List(); foreach (string dll in assemblies) { if (string.Compare(dll, Path.Combine(ProjectFactory.Instance.ProjectDirectory, Path.GetFileName(dll)), true) != 0) @@ -83,8 +84,22 @@ namespace VisualPascalABC } } - //ProjectFactory.Instance.AddReferences(assm_lst.ToArray()); - } + + //ProjectFactory.Instance.AddReferences(assm_lst.ToArray()); + foreach (string ndll in native_dlls) + { + try + { + var destndllname = Path.Combine(ProjectFactory.Instance.ProjectDirectory, Path.GetFileName(ndll)); + File.Copy(ndll, destndllname, true); + } + catch + { + + } + } + + } } } diff --git a/VisualPascalABCNET/Projects/ReferenceForm.cs b/VisualPascalABCNET/Projects/ReferenceForm.cs index 7e51d999b..b13266721 100644 --- a/VisualPascalABCNET/Projects/ReferenceForm.cs +++ b/VisualPascalABCNET/Projects/ReferenceForm.cs @@ -43,7 +43,8 @@ namespace VisualPascalABC } private List assembly_files = new List(); - public bool fromFile = false; + private List native_dlls = new List(); + public bool fromFile = false; private AssemblyType assemblyType = AssemblyType.GAC; public AssemblyType AssemblyType @@ -67,8 +68,9 @@ namespace VisualPascalABC public void Clear() { - assembly_files.Clear(); - assemblyType = AssemblyType.GAC; + assembly_files.Clear(); + native_dlls.Clear(); + assemblyType = AssemblyType.GAC; lvGac.Items.Clear(); tbLog.Text = ""; //lvCom.Items.Clear(); @@ -101,8 +103,13 @@ namespace VisualPascalABC { return assembly_files.ToArray(); } - - private List GetCacheContent() + + public string[] GetNativeDlls() + { + return native_dlls.ToArray(); + } + + private List GetCacheContent() { List itemList = new List(); foreach (GacInterop.AssemblyListEntry asm in GacInterop.GetAssemblyList()) { @@ -154,13 +161,15 @@ namespace VisualPascalABC } } - private void nugetInstalled(bool result, string[] dlls, string[] xmls) + private void nugetInstalled(bool result, string[] dlls, string[] xmls, string[] ndlls) { assemblyType = AssemblyType.File; if (result) { foreach (string dll in dlls) assembly_files.Add(dll); + foreach (string dll in ndlls) + native_dlls.Add(dll); this.DialogResult = DialogResult.OK; } else