From b79335c92024ddbcaada67d10114b344701d157b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 19 Apr 2026 21:30:16 +0200 Subject: [PATCH] Fix compiling C# scripts that use `nuget` package to properly resolve it on 1st build --- Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs | 8 ++++++++ Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs index 164cd412f..4afb57bd1 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs @@ -284,9 +284,17 @@ namespace Flax.Build if (buildData.TargetOptions.NugetPackageReferences.Any()) { var nugetPath = Utilities.GetNugetPackagesPath(); + var restoreOnce = true; foreach (var reference in buildOptions.NugetPackageReferences) { var path = reference.GetLibPath(nugetPath); + if (!File.Exists(path) && restoreOnce) + { + // Package binaries folder is missing so restore packages (incl. dependency packages) + RestoreNugetPackages(graph, buildOptions.Target, buildOptions); + restoreOnce = false; + path = reference.GetLibPath(nugetPath); + } args.Add(string.Format("/reference:\"{0}\"", path)); } } diff --git a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs index 8251ff186..9cca0dfa6 100644 --- a/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs +++ b/Source/Tools/Flax.Build/Build/NativeCpp/BuildOptions.cs @@ -139,7 +139,9 @@ namespace Flax.Build.NativeCpp { if (libFolder == null) libFolder = GetLibFolder(nugetPath); - var dlls = Directory.GetFiles(libFolder, "*.dll", SearchOption.TopDirectoryOnly); + if (libFolder == string.Empty) + return string.Empty; + var dlls = Directory.Exists(libFolder) ? Directory.GetFiles(libFolder, "*.dll", SearchOption.TopDirectoryOnly) : []; if (dlls.Length == 0) { Log.Error($"Missing NuGet package \"{Name}, {Version}, {Framework}\" binaries (folder: {libFolder})");