diff --git a/Source/Bake.Tests/IntegrationTests/BakeTests/NetCoreConsoleTests.cs b/Source/Bake.Tests/IntegrationTests/BakeTests/NetCoreConsoleTests.cs index f8fe102c..c7a4e156 100644 --- a/Source/Bake.Tests/IntegrationTests/BakeTests/NetCoreConsoleTests.cs +++ b/Source/Bake.Tests/IntegrationTests/BakeTests/NetCoreConsoleTests.cs @@ -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)] diff --git a/Source/Bake.Tests/IntegrationTests/ServiceTests/DotNetComposerServiceTests.cs b/Source/Bake.Tests/IntegrationTests/ServiceTests/DotNetComposerServiceTests.cs index 7dde5904..e30413d7 100644 --- a/Source/Bake.Tests/IntegrationTests/ServiceTests/DotNetComposerServiceTests.cs +++ b/Source/Bake.Tests/IntegrationTests/ServiceTests/DotNetComposerServiceTests.cs @@ -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; @@ -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() + .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() + .Single() + .ExecutableFileName + .ShouldBe("NetCore.Console.dll"); + } + protected override IServiceCollection Configure(IServiceCollection serviceCollection) { return base.Configure(serviceCollection) diff --git a/Source/Bake/Cooking/Composers/DotNetComposer.cs b/Source/Bake/Cooking/Composers/DotNetComposer.cs index 5bbfa6b0..c79863b7 100644 --- a/Source/Bake/Cooking/Composers/DotNetComposer.cs +++ b/Source/Bake/Cooking/Composers/DotNetComposer.cs @@ -315,6 +315,10 @@ private IEnumerable 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, @@ -324,18 +328,26 @@ private IEnumerable 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(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, diff --git a/Source/Bake/Services/Tools/DotNet.cs b/Source/Bake/Services/Tools/DotNet.cs index 68bc2ea8..fda9def2 100644 --- a/Source/Bake/Services/Tools/DotNet.cs +++ b/Source/Bake/Services/Tools/DotNet.cs @@ -276,7 +276,16 @@ public async Task 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",