diff --git a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs index 75a916296..895810e9e 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/Builder.DotNet.cs @@ -143,12 +143,39 @@ namespace Flax.Build graph.AddCopyFile(dstFile, srcFile); } - var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); - foreach (var reference in targetBuildOptions.NugetPackageReferences) + if (targetBuildOptions.NugetPackageReferences.Any()) { - var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll"); - var dstFile = Path.Combine(outputPath, Path.GetFileName(path)); - graph.AddCopyFile(dstFile, path); + var buildPlatform = Platform.BuildTargetPlatform; + var dotnetSdk = DotNetSdk.Instance; + if (!dotnetSdk.IsValid) + throw new DotNetSdk.MissingException(); + var dotnetPath = "dotnet"; + switch (buildPlatform) + { + case TargetPlatform.Windows: + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); + break; + case TargetPlatform.Linux: break; + case TargetPlatform.Mac: + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet"); + break; + default: throw new InvalidPlatformException(buildPlatform); + } + var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); + foreach (var reference in targetBuildOptions.NugetPackageReferences) + { + var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll"); + if (!File.Exists(path)) + { + var task = graph.Add(); + task.WorkingDirectory = target.FolderPath; + task.InfoMessage = $"Adding Nuget Package: {reference.Name}, Version {reference.Version}"; + task.CommandPath = dotnetPath; + task.CommandArguments = $"add package {reference.Name} --version {reference.Version}"; + } + var dstFile = Path.Combine(outputPath, Path.GetFileName(path)); + graph.AddCopyFile(dstFile, path); + } } } } diff --git a/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs b/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs index 664bfb63f..beaebbb2d 100644 --- a/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs +++ b/Source/Tools/Flax.Build/Build/NativeCpp/Builder.NativeCpp.cs @@ -1057,12 +1057,39 @@ namespace Flax.Build var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile)); graph.AddCopyFile(dstFile, srcFile); } - var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); - foreach (var reference in targetBuildOptions.NugetPackageReferences) + if (targetBuildOptions.NugetPackageReferences.Any()) { - var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll"); - var dstFile = Path.Combine(outputPath, Path.GetFileName(path)); - graph.AddCopyFile(dstFile, path); + var buildPlatform = Platform.BuildTargetPlatform; + var dotnetSdk = DotNetSdk.Instance; + if (!dotnetSdk.IsValid) + throw new DotNetSdk.MissingException(); + var dotnetPath = "dotnet"; + switch (buildPlatform) + { + case TargetPlatform.Windows: + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); + break; + case TargetPlatform.Linux: break; + case TargetPlatform.Mac: + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet"); + break; + default: throw new InvalidPlatformException(buildPlatform); + } + var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); + foreach (var reference in targetBuildOptions.NugetPackageReferences) + { + var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll"); + if (!File.Exists(path)) + { + var task = graph.Add(); + task.WorkingDirectory = target.FolderPath; + task.InfoMessage = $"Adding Nuget Package: {reference.Name}, Version {reference.Version}"; + task.CommandPath = dotnetPath; + task.CommandArguments = $"add package {reference.Name} --version {reference.Version}"; + } + var dstFile = Path.Combine(outputPath, Path.GetFileName(path)); + graph.AddCopyFile(dstFile, path); + } } } } @@ -1264,12 +1291,40 @@ namespace Flax.Build var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile)); graph.AddCopyFile(dstFile, srcFile); } - var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); - foreach (var reference in targetBuildOptions.NugetPackageReferences) + + if (targetBuildOptions.NugetPackageReferences.Any()) { - var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll"); - var dstFile = Path.Combine(outputPath, Path.GetFileName(path)); - graph.AddCopyFile(dstFile, path); + var buildPlatform = Platform.BuildTargetPlatform; + var dotnetSdk = DotNetSdk.Instance; + if (!dotnetSdk.IsValid) + throw new DotNetSdk.MissingException(); + var dotnetPath = "dotnet"; + switch (buildPlatform) + { + case TargetPlatform.Windows: + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet.exe"); + break; + case TargetPlatform.Linux: break; + case TargetPlatform.Mac: + dotnetPath = Path.Combine(dotnetSdk.RootPath, "dotnet"); + break; + default: throw new InvalidPlatformException(buildPlatform); + } + var nugetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"); + foreach (var reference in targetBuildOptions.NugetPackageReferences) + { + var path = Path.Combine(nugetPath, reference.Name, reference.Version, "lib", reference.Framework, $"{reference.Name}.dll"); + if (!File.Exists(path)) + { + var task = graph.Add(); + task.WorkingDirectory = target.FolderPath; + task.InfoMessage = $"Adding Nuget Package: {reference.Name}, Version {reference.Version}"; + task.CommandPath = dotnetPath; + task.CommandArguments = $"add package {reference.Name} --version {reference.Version}"; + } + var dstFile = Path.Combine(outputPath, Path.GetFileName(path)); + graph.AddCopyFile(dstFile, path); + } } } }