diff --git a/Source/Tools/Flax.Build/Build/Builder.cs b/Source/Tools/Flax.Build/Build/Builder.cs index 3b00daf72..d09947f09 100644 --- a/Source/Tools/Flax.Build/Build/Builder.cs +++ b/Source/Tools/Flax.Build/Build/Builder.cs @@ -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(); 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); } } } diff --git a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs index ea1eb1ade..b0f116673 100644 --- a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs +++ b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs @@ -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]; } }