Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ private void AssertSuccessfulArtifacts()
"bin", "Release", "publish", "win-x64", "NetCore.Console.exe");
AssertFileExists(
50L.MB(),
"bin", "Release", "publish", "osx-arm64", "NetCore.Console");
"bin",
"Release",
"publish",
"osx-arm64",
OperatingSystem.IsLinux()
? "NetCore.Console.dll"
: "NetCore.Console");
}

[TestCase(ExitCodes.Core.NoCommand)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using Bake.Services;
using Bake.Tests.Helpers;
using Bake.ValueObjects;
using Bake.ValueObjects.Artifacts;
using Bake.ValueObjects.Recipes.DotNet;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Shouldly;
Expand Down Expand Up @@ -57,6 +59,42 @@ public async Task TestIt()
var _ = await recipesTask;
}

[Test]
public async Task OsxArm64PublishRecipeUsesFrameworkDependentSettingsOnLinux()
{
if (!OperatingSystem.IsLinux())
{
Assert.Ignore("This behavior is only expected on Linux hosts.");
}

// Arrange
var ingredients = Ingredients.New(
SemVer.With(1, 2, 3),
WorkingDirectory);

// Act
var recipesTask = Sut.ComposeAsync(
Context.New(ingredients),
CancellationToken.None);
ingredients.FailOutstanding();
var recipes = await recipesTask;

// Assert
var osxArm64PublishRecipe = recipes
.OfType<DotNetPublishRecipe>()
.Single(r => r.Platform.Os == ExecutableOperatingSystem.MacOSX &&
r.Platform.Arch == ExecutableArchitecture.Arm64);

osxArm64PublishRecipe.PublishSingleFile.ShouldBeFalse();
osxArm64PublishRecipe.SelfContained.ShouldBeFalse();
osxArm64PublishRecipe.Properties["UseAppHost"].ShouldBe("false");
osxArm64PublishRecipe.Artifacts
.OfType<ExecutableArtifact>()
.Single()
.ExecutableFileName
.ShouldBe("NetCore.Console.dll");
}

protected override IServiceCollection Configure(IServiceCollection serviceCollection)
{
return base.Configure(serviceCollection)
Expand Down
20 changes: 16 additions & 4 deletions Source/Bake/Cooking/Composers/DotNetComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ private IEnumerable<Recipe> CreateRecipe(
foreach (var visualStudioProject in visualStudioSolution.Projects.Where(p => p.CsProj.PackAsTool))
foreach (var targetPlatform in ingredients.Platforms)
{
var useFrameworkDependentPublish = OperatingSystem.IsLinux() &&
targetPlatform.Os == ExecutableOperatingSystem.MacOSX &&
targetPlatform.Arch == ExecutableArchitecture.Arm64;

var path = Path.Combine(
"bin",
configuration,
Expand All @@ -324,18 +328,26 @@ private IEnumerable<Recipe> CreateRecipe(
var outputDirectory = Path.Combine(visualStudioProject.Directory, path);
var executableFileName = targetPlatform.Os == ExecutableOperatingSystem.Windows
? $"{visualStudioProject.AssemblyName}.exe"
: visualStudioProject.AssemblyName;
: useFrameworkDependentPublish
? $"{visualStudioProject.AssemblyName}.dll"
: visualStudioProject.AssemblyName;
var publishProperties = useFrameworkDependentPublish
? new Dictionary<string, string>(properties)
{
["UseAppHost"] = "false"
}
: properties;

yield return new DotNetPublishRecipe(
visualStudioProject.Path,
true,
true,
!useFrameworkDependentPublish,
!useFrameworkDependentPublish,
true,
configuration,
targetPlatform,
path,
ingredients.Version,
properties,
publishProperties,
new ExecutableArtifact(
visualStudioProject.CsProj.ToolCommandName,
outputDirectory,
Expand Down
11 changes: 10 additions & 1 deletion Source/Bake/Services/Tools/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,16 @@ public async Task<IToolResult> PublishAsync(

AddIf(!argument.Build, arguments, "--no-build");
AddIf(argument.PublishSingleFile, arguments, "-p:PublishSingleFile=true");
AddIf(argument.SelfContained, arguments, "--self-contained", "true");
var useAppHostDisabled = argument.Properties.TryGetValue("UseAppHost", out var useAppHost) &&
useAppHost.Equals("false", StringComparison.OrdinalIgnoreCase);
if (argument.SelfContained)
{
arguments.AddRange(["--self-contained", "true"]);
}
else if (useAppHostDisabled)
{
arguments.AddRange(["--self-contained", "false"]);
}

var buildRunner = _runnerFactory.CreateRunner(
"dotnet",
Expand Down