Fix deploying NuGet packages to include correct library file name

#3900
This commit is contained in:
Wojtek Figat
2026-01-22 19:57:16 +01:00
parent ecfd03f79c
commit 6dbfd25bdb
2 changed files with 41 additions and 8 deletions

View File

@@ -438,18 +438,38 @@ namespace Flax.Build
if (targetBuildOptions.NugetPackageReferences.Any())
{
// Find all packages to deploy (incl. dependencies) and restore if needed
var nugetPath = Utilities.GetNugetPackagesPath();
var restore = true;
var restoreOnce = true;
var nugetFiles = new HashSet<string>();
foreach (var reference in targetBuildOptions.NugetPackageReferences)
{
var path = reference.GetLibPath(nugetPath);
if (!File.Exists(path) && restore)
var folder = reference.GetLibFolder(nugetPath);
if (!Directory.Exists(folder) && restoreOnce)
{
// Package binaries folder is missing so restore packages (incl. dependency packages)
RestoreNugetPackages(graph, target, targetBuildOptions);
restore = false;
restoreOnce = false;
}
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
graph.AddCopyFile(dstFile, path);
// Deploy library
var path = reference.GetLibPath(nugetPath, folder);
nugetFiles.Add(path);
// Copy additional files (if included)
path = Path.ChangeExtension(path, "xml");
if (File.Exists(path))
nugetFiles.Add(path);
path = Path.ChangeExtension(path, "pdb");
if (targetBuildOptions.Configuration != TargetConfiguration.Release && File.Exists(path))
nugetFiles.Add(path);
}
// Copy libraries from all referenced packages to the output folder
foreach (var file in nugetFiles)
{
var dstFile = Path.Combine(outputPath, Path.GetFileName(file));
graph.AddCopyFile(dstFile, file);
}
}
}

View File

@@ -103,9 +103,22 @@ namespace Flax.Build.NativeCpp
Framework = framework;
}
internal string GetLibPath(string nugetPath)
internal string GetLibFolder(string nugetPath)
{
return Path.Combine(nugetPath, Name, Version, "lib", Framework, $"{Name}.dll");
return Path.Combine(nugetPath, Name, Version, "lib", Framework);
}
internal string GetLibPath(string nugetPath, string libFolder = null)
{
if (libFolder == null)
libFolder = GetLibFolder(nugetPath);
var dlls = Directory.GetFiles(libFolder, "*.dll", SearchOption.TopDirectoryOnly);
if (dlls.Length == 0)
{
Log.Error($"Missing NuGet package \"{Name}, {Version}, {Framework}\" binaries (folder: {libFolder})");
return string.Empty;
}
return dlls[0];
}
}