Skip to content

Commit

Permalink
Merge pull request #4114 from wli3/disable-useapphost-on-mac-by-defau…
Browse files Browse the repository at this point in the history
…lt-3.1.1xx

disable useapphost on mac by default
  • Loading branch information
William Li authored Jan 15, 2020
2 parents 801d77c + 19eebd5 commit 595244a
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ Copyright (c) .NET Foundation. All rights reserved.
SelfContained was not an option in .NET Core SDK 1.0.
Default SelfContained based on the RuntimeIdentifier, so projects don't have to explicitly set SelfContained.
This avoids a breaking change from 1.0 behavior.
Due to https://github.com/dotnet/sdk/issues/4012 we decided to disable UseAppHost to be the default on mac
-->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'">
<SelfContained Condition="'$(SelfContained)' == '' and '$(RuntimeIdentifier)' != ''">true</SelfContained>
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
<_OnOsx>$(NETCoreSdkRuntimeIdentifier.StartsWith('osx'))</_OnOsx>
<UseAppHost Condition="'$(UseAppHost)' == '' and
('$(SelfContained)' == 'true' or
('$(RuntimeIdentifier)' != '' and '$(_TargetFrameworkVersionWithoutV)' >= '2.1') or
'$(_TargetFrameworkVersionWithoutV)' >= '3.0')">true</UseAppHost>
('$(_TargetFrameworkVersionWithoutV)' >= '3.0' and $(_OnOsx) != 'true'))">true</UseAppHost>
<UseAppHost Condition="'$(UseAppHost)' == ''">false</UseAppHost>
</PropertyGroup>

Expand Down
45 changes: 43 additions & 2 deletions src/Tests/Microsoft.NET.Build.Tests/AppHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text.RegularExpressions;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
Expand All @@ -24,7 +26,7 @@ public AppHostTests(ITestOutputHelper log) : base(log)
{
}

[Theory]
[PlatformSpecificTheory(Platform.Windows, Platform.Linux, Platform.FreeBSD)]
[InlineData("netcoreapp3.0")]
public void It_builds_a_runnable_apphost_by_default(string targetFramework)
{
Expand Down Expand Up @@ -63,11 +65,47 @@ public void It_builds_a_runnable_apphost_by_default(string targetFramework)
.HaveStdOutContaining("Hello World!");
}

[PlatformSpecificFact(Platform.Darwin)]
public void It_builds_a_runnable_apphost_if_opt_in_on_mac()
{
var targetFramework = "netcoreapp3.0";
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: targetFramework)
.WithSource()
.WithTargetFramework(targetFramework);

var buildCommand = new BuildCommand(Log, testAsset.TestRoot);
buildCommand
.Execute(new string[] {
"/restore", "/p:UseAppHost=true",
})
.Should()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);
var hostExecutable = $"HelloWorld{Constants.ExeSuffix}";

outputDirectory.Should().OnlyHaveFiles(new[] {
hostExecutable,
"HelloWorld.dll",
"HelloWorld.pdb",
"HelloWorld.deps.json",
"HelloWorld.runtimeconfig.dev.json",
"HelloWorld.runtimeconfig.json",
});
}

[Theory]
[InlineData("netcoreapp2.1")]
[InlineData("netcoreapp2.2")]
public void It_does_not_build_with_an_apphost_by_default_before_netcoreapp_3(string targetFramework)
[InlineData("netcoreapp3.0")] // only on macOS
public void It_does_not_build_with_an_apphost_by_default_before_netcoreapp_3_or_macOs(string targetFramework)
{
if (targetFramework == "netcoreapp3.0" && RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
return;
}

var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: targetFramework)
.WithSource()
Expand Down Expand Up @@ -230,6 +268,9 @@ public void It_retries_on_failure_to_create_apphost()
IsSdkProject = true,
IsExe = true,
};

// enable generating apphost even on macOS
testProject.AdditionalProperties.Add("UseApphost", "true");

var testAsset = _testAssetsManager.CreateTestProject(testProject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using FluentAssertions;

using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
Expand Down Expand Up @@ -53,8 +54,9 @@ public void It_copies_local_package_dependencies_on_build()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks);
outputDirectory.Should().OnlyHaveFiles(new[] {
$"{ProjectName}{Constants.ExeSuffix}",

var expectedFiles = new []
{
$"{ProjectName}.deps.json",
$"{ProjectName}.dll",
$"{ProjectName}.pdb",
Expand All @@ -65,7 +67,9 @@ public void It_copies_local_package_dependencies_on_build()
"runtimes/osx-x64/native/libsqlite3.dylib",
"runtimes/win7-x64/native/sqlite3.dll",
"runtimes/win7-x86/native/sqlite3.dll"
});
};

outputDirectory.Should().OnlyHaveFiles(AssertionHelper.AppendApphostOnNonMacOS(ProjectName, expectedFiles));
}

[Fact]
Expand Down Expand Up @@ -93,14 +97,13 @@ public void It_does_not_copy_local_package_dependencies_when_requested_not_to()
buildCommand.Execute().Should().Pass();

var outputDirectory = buildCommand.GetOutputDirectory(testProject.TargetFrameworks);
outputDirectory.Should().OnlyHaveFiles(new[] {
$"{ProjectName}{Constants.ExeSuffix}",
outputDirectory.Should().OnlyHaveFiles(AssertionHelper.AppendApphostOnNonMacOS(ProjectName, new[] {
$"{ProjectName}.deps.json",
$"{ProjectName}.dll",
$"{ProjectName}.pdb",
$"{ProjectName}.runtimeconfig.dev.json",
$"{ProjectName}.runtimeconfig.json",
});
}));
}

// Core MSBuild only because CI machines don't have updated VS (with support for RuntimeIdentifierGraphPath)
Expand Down Expand Up @@ -144,7 +147,7 @@ public void It_copies_local_specific_runtime_package_dependencies_on_build()
$"{ProjectName}.runtimeconfig.json",
"Newtonsoft.Json.dll",
// NOTE: this may break in the future when the SDK supports platforms that sqlite does not
$"{FileConstants.DynamicLibPrefix}sqlite3{FileConstants.DynamicLibSuffix}",
$"{FileConstants.DynamicLibPrefix}sqlite3{FileConstants.DynamicLibSuffix}"
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using System.Text;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Xunit;
using Xunit.Abstractions;
using RuntimeEnvironment = System.Runtime.InteropServices.RuntimeEnvironment;

namespace Microsoft.NET.Build.Tests
{
Expand Down Expand Up @@ -75,7 +77,7 @@ public void It_only_publish_selected_ResourceLanguages(string targetFramework, b
$"{testProject.Name}.runtimeconfig.dev.json"
});

if (testProject.TargetFrameworks == "netcoreapp3.0")
if (testProject.TargetFrameworks == "netcoreapp3.0" && Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
expectedFiles.Add($"{testProject.Name}{Constants.ExeSuffix}");
}
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseVB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Xunit;
using System;
using System.IO;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.NET.TestFramework.ProjectConstruction;

namespace Microsoft.NET.Build.Tests
Expand Down Expand Up @@ -132,15 +133,14 @@ private static (VBRuntime, string[]) GetExpectedOutputs(string targetFramework,
});

case ("netcoreapp3.0", true):
return (VBRuntime.Referenced, new[]
return (VBRuntime.Referenced, AssertionHelper.AppendApphostOnNonMacOS("HelloWorld", new[]
{
"HelloWorld.dll",
"HelloWorld.pdb",
"HelloWorld" + EnvironmentInfo.ExecutableExtension,
"HelloWorld.runtimeconfig.json",
"HelloWorld.runtimeconfig.dev.json",
"HelloWorld.deps.json",
});
}));

case ("netcoreapp3.0", false):
return (VBRuntime.Referenced, new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Xunit.Abstractions;
using System.Collections.Generic;
using Microsoft.NET.TestFramework.ProjectConstruction;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace Microsoft.NET.Publish.Tests
{
Expand Down Expand Up @@ -60,7 +61,7 @@ public void It_does_not_publish_a_PackageReference_with_PrivateAssets_All(string
"HelloWorld.runtimeconfig.json"
};

if (shouldIncludeExecutable)
if (shouldIncludeExecutable && RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
expectedFiles.Add("HelloWorld" + EnvironmentInfo.ExecutableExtension);
}
Expand Down Expand Up @@ -105,7 +106,7 @@ public void It_does_not_publish_a_PackageReference_with_Publish_false(string tar
"HelloWorld.runtimeconfig.json"
};

if (shouldIncludeExecutable)
if (shouldIncludeExecutable && RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
expectedFiles.Add("HelloWorld" + EnvironmentInfo.ExecutableExtension);
}
Expand Down Expand Up @@ -157,7 +158,7 @@ public void It_publishes_a_PackageReference_with_PrivateAssets_All_and_Publish_t
expectedFiles.Add("System.Runtime.Serialization.Primitives.dll");
}

if (shouldIncludeExecutable)
if (shouldIncludeExecutable && RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
expectedFiles.Add("HelloWorld" + EnvironmentInfo.ExecutableExtension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Xml.Linq;
using Xunit.Abstractions;
using Microsoft.NET.TestFramework.ProjectConstruction;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace Microsoft.NET.Publish.Tests
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public void It_only_publishes_selected_ResourceLanguages(string tfm)
$"{testProject.Name}.runtimeconfig.json"
};

if (tfm == "netcoreapp3.0")
if (tfm == "netcoreapp3.0" && RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
files.Add($"{testProject.Name}{Constants.ExeSuffix}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using Microsoft.Extensions.DependencyModel;
using Xunit.Abstractions;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace Microsoft.NET.Publish.Tests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
Expand Down Expand Up @@ -80,15 +81,23 @@ public void GroupNotPopulatedWithoutRid()
Log.WriteLine("Contents of PublishItemsOutputGroup dumped to '{0}'.", testOutputDir.FullName);

// Since no RID was specified the output group should only contain framework dependent output
testOutputDir.Should().HaveFile($"{testProject.Name}{Constants.ExeSuffix}");
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
testOutputDir.Should().HaveFile($"{testProject.Name}{Constants.ExeSuffix}");
}

testOutputDir.Should().HaveFile($"{testProject.Name}.deps.json");
testOutputDir.Should().NotHaveFiles(FrameworkAssemblies);

var testKeyOutputDir = new DirectoryInfo(Path.Combine(testAsset.Path, testProject.Name, "TestOutput_Key"));
Log.WriteLine("PublishItemsOutputGroup key items dumped to '{0}'.", testKeyOutputDir.FullName);

// Verify the only key item is the exe
testKeyOutputDir.Should().OnlyHaveFiles(new List<string>() { $"{testProject.Name}{Constants.ExeSuffix}" });
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
// Verify the only key item is the exe
testKeyOutputDir.Should()
.OnlyHaveFiles(new List<string>() {$"{testProject.Name}{Constants.ExeSuffix}"});
}
}

private TestProject SetupProject()
Expand Down
18 changes: 18 additions & 0 deletions src/Tests/Microsoft.NET.TestFramework/AssertionHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Linq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;

public static class AssertionHelper
{
public static string[] AppendApphostOnNonMacOS(string ProjectName, string[] expectedFiles)
{
string apphost = $"{ProjectName}{Constants.ExeSuffix}";
// No UseApphost is false by default on macOS
return RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin
? expectedFiles.Append(apphost).ToArray()
: expectedFiles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.DotNet.PlatformAbstractions;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

namespace Microsoft.NET.ToolPack.Tests
{
Expand Down Expand Up @@ -153,12 +154,15 @@ public void It_does_not_contain_apphost_exe(bool multiTarget)
"RunCommand",
GetValuesCommand.ValueType.Property);

getValuesCommand.Execute();
string runCommandPath = getValuesCommand.GetValues().Single();
Path.GetExtension(runCommandPath)
.Should().Be(extension);
File.Exists(runCommandPath).Should()
.BeTrue("run command should be apphost executable (for WinExe) to debug. But it will not be packed");
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Darwin)
{
getValuesCommand.Execute();
string runCommandPath = getValuesCommand.GetValues().Single();
Path.GetExtension(runCommandPath)
.Should().Be(extension);
File.Exists(runCommandPath).Should()
.BeTrue("run command should be apphost executable (for WinExe) to debug. But it will not be packed");
}
}

[Theory]
Expand Down

0 comments on commit 595244a

Please sign in to comment.