Add utility methods for redundant code.
This commit is contained in:
@@ -145,34 +145,12 @@ namespace Flax.Build
|
||||
|
||||
if (targetBuildOptions.NugetPackageReferences.Any())
|
||||
{
|
||||
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>();
|
||||
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}";
|
||||
}
|
||||
Utilities.AddNugetPackage(graph, target, reference);
|
||||
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
|
||||
graph.AddCopyFile(dstFile, path);
|
||||
}
|
||||
|
||||
@@ -1057,36 +1057,15 @@ namespace Flax.Build
|
||||
var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile));
|
||||
graph.AddCopyFile(dstFile, srcFile);
|
||||
}
|
||||
|
||||
if (targetBuildOptions.NugetPackageReferences.Any())
|
||||
{
|
||||
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>();
|
||||
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}";
|
||||
}
|
||||
Utilities.AddNugetPackage(graph, target, reference);
|
||||
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
|
||||
graph.AddCopyFile(dstFile, path);
|
||||
}
|
||||
@@ -1291,37 +1270,15 @@ namespace Flax.Build
|
||||
var dstFile = Path.Combine(outputPath, Path.GetFileName(srcFile));
|
||||
graph.AddCopyFile(dstFile, srcFile);
|
||||
}
|
||||
|
||||
|
||||
if (targetBuildOptions.NugetPackageReferences.Any())
|
||||
{
|
||||
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>();
|
||||
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}";
|
||||
}
|
||||
Utilities.AddNugetPackage(graph, target, reference);
|
||||
var dstFile = Path.Combine(outputPath, Path.GetFileName(path));
|
||||
graph.AddCopyFile(dstFile, path);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,49 @@ namespace Flax.Build
|
||||
/// </summary>
|
||||
public static class Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the .Net SDK path.
|
||||
/// </summary>
|
||||
/// <returns>The path.</returns>
|
||||
public static string GetDotNetPath()
|
||||
{
|
||||
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);
|
||||
}
|
||||
return dotnetPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads a nuget package.
|
||||
/// </summary>
|
||||
/// <param name="graph">The task graph.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="dotNetPath">The dotnet path.</param>
|
||||
/// <param name="package"></param>
|
||||
public static void AddNugetPackage(Graph.TaskGraph graph, Target target, NativeCpp.NugetPackage package)
|
||||
{
|
||||
var dotNetPath = GetDotNetPath();
|
||||
var task = graph.Add<Graph.Task>();
|
||||
task.WorkingDirectory = target.FolderPath;
|
||||
task.InfoMessage = $"Add Nuget Package: {package.Name}, Version {package.Version}";
|
||||
task.CommandPath = dotNetPath;
|
||||
//task.CommandArguments = $"add package {package.Name} --version {package.Version}";
|
||||
task.CommandArguments = $"restore";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the hash code for the string (the same for all platforms). Matches Engine algorithm for string hashing.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user