nuget - инсталляция сборок с учетом папки netstandard2.0

и копирование нативных dll из папок runtimes\win-x64\native\
This commit is contained in:
Mikhalkovich Stanislav 2023-04-19 19:53:42 +03:00
parent 65bdec22a0
commit bf82785f87
3 changed files with 73 additions and 17 deletions

View file

@ -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<string> dllList = new List<string>();
List<string> xmlList = new List<string>();
List<string> nativedllList = new List<string>();
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;
}
}

View file

@ -50,7 +50,8 @@ namespace VisualPascalABC
else
{
string[] assemblies = ReferenceForm.Instance.GetSelectedFileAssemblies();
List<string> assm_lst = new List<string>();
string[] native_dlls = ReferenceForm.Instance.GetNativeDlls();
List<string> assm_lst = new List<string>();
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
{
}
}
}
}
}

View file

@ -43,7 +43,8 @@ namespace VisualPascalABC
}
private List<string> assembly_files = new List<string>();
public bool fromFile = false;
private List<string> native_dlls = new List<string>();
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<ListViewItem> GetCacheContent()
public string[] GetNativeDlls()
{
return native_dlls.ToArray();
}
private List<ListViewItem> GetCacheContent()
{
List<ListViewItem> itemList = new List<ListViewItem>();
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