Skip to content

Commit

Permalink
fix(execution): include original nuget packages in requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Jul 14, 2024
1 parent 3109f4c commit 8dd7fe4
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions source/Nuke.Build/Execution/ToolRequirementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ public static void EnsureToolRequirements(INukeBuild build, IReadOnlyCollection<
{
var requirements = build.GetType().GetCustomAttributes<RequiresAttribute>().Select(x => x.GetRequirement())
.Concat(executionPlan.SelectMany(x => x.ToolRequirements)).ToList();
var directory = build.TemporaryDirectory;

InstallNuGetPackages(requirements.OfType<NuGetPackageRequirement>().ToList(), directory);
InstallNpmPackages(requirements.OfType<NpmPackageRequirement>().ToList(), directory);
InstallAptGetPackages(requirements.OfType<AptGetPackageRequirement>().ToList(), directory);
InstallNuGetPackages(requirements.OfType<NuGetPackageRequirement>().ToList(), build);
InstallNpmPackages(requirements.OfType<NpmPackageRequirement>().ToList(), build);
InstallAptGetPackages(requirements.OfType<AptGetPackageRequirement>().ToList(), build);
}

private static void InstallNuGetPackages(IReadOnlyCollection<NuGetPackageRequirement> requirements, AbsolutePath directory)
private static void InstallNuGetPackages(IReadOnlyCollection<NuGetPackageRequirement> requirements, INukeBuild build)
{
if (requirements.Count == 0)
return;

var projectFile = directory / "nuget.csproj";
var projectFile = build.TemporaryDirectory / "nuget.csproj";
NuGetToolPathResolver.NuGetPackagesConfigFile = projectFile;
NuGetToolPathResolver.NuGetAssetsConfigFile = projectFile.Parent / "obj" / "project.assets.json";

Expand All @@ -45,8 +44,10 @@ private static void InstallNuGetPackages(IReadOnlyCollection<NuGetPackageRequire
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<Import Project="{build.BuildProjectFile}" />

<ItemGroup>
{groupedPackages.Select(x => $""" <PackageDownload Include="{x.Key}" Version="{x.JoinSemicolon()}" />""").JoinNewLine()}
{groupedPackages.Select(x => $""" <PackageDownload Include="{x.Key}" Version="{x.JoinSemicolon()}" Exclude="@(PackageDownload)" />""").JoinNewLine()}
</ItemGroup>

</Project>
Expand All @@ -63,12 +64,12 @@ private static void InstallNuGetPackages(IReadOnlyCollection<NuGetPackageRequire
dotnet.Invoke($"restore", workingDirectory: projectFile.Parent, logInvocation: false, logOutput: false);
}

private static void InstallNpmPackages(IReadOnlyCollection<NpmPackageRequirement> requirements, AbsolutePath directory)
private static void InstallNpmPackages(IReadOnlyCollection<NpmPackageRequirement> requirements, INukeBuild build)
{
if (requirements.Count == 0)
return;

var packageJsonFile = directory / "package.json";
var packageJsonFile = build.TemporaryDirectory / "package.json";
NpmToolPathResolver.NpmPackageJsonFile = packageJsonFile;

var packages = requirements.OrderBy(x => x.PackageId).ToList();
Expand All @@ -92,15 +93,15 @@ private static void InstallNpmPackages(IReadOnlyCollection<NpmPackageRequirement
npm.Invoke("install", workingDirectory: packageJsonFile.Parent, logInvocation: false, logOutput: false);
}

private static void InstallAptGetPackages(IReadOnlyCollection<AptGetPackageRequirement> requirements, AbsolutePath directory)
private static void InstallAptGetPackages(IReadOnlyCollection<AptGetPackageRequirement> requirements, INukeBuild build)
{
if (requirements.Count == 0)
return;

var packages = requirements.OrderBy(x => x.PackageId).ToList();
Assert.True(EnvironmentInfo.IsLinux, "AptGet is only available on Linux");

var installScript = directory / "apt-get.sh";
var installScript = build.TemporaryDirectory / "apt-get.sh";

var content = $"""
apt-get update
Expand Down

0 comments on commit 8dd7fe4

Please sign in to comment.