diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets index 2f96be51bb60..d5c82388431b 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets @@ -74,11 +74,6 @@ NOTE: This file is imported from the following contexts, so be aware when writin <_InnerToolsPublishAot Condition="$(_HasRIDSpecificTools) and '$(PublishAot)' == 'true'">true false - - false - - true - <_ToolPackageShouldIncludeImplementation Condition=" '$(PackAsTool)' == 'true' And @@ -132,14 +127,27 @@ NOTE: This file is imported from the following contexts, so be aware when writin + + + <_ToolUsesPlatformSpecificExecutable Condition="$(_IsRidSpecific) and ('$(UseAppHost)' == 'true' or '$(PublishAot)' == 'true')">true + <_ToolUsesPlatformSpecificExecutable Condition="'$(_ToolUsesPlatformSpecificExecutable)' == ''">false + + + + dotnet + executable + + - $(TargetFileName) - $(AssemblyName)$(_NativeExecutableExtension) + $(TargetFileName) + $(AssemblyName)$(_NativeExecutableExtension) - + $(PackageId).$(RuntimeIdentifier) @@ -157,7 +165,7 @@ NOTE: This file is imported from the following contexts, so be aware when writin - @@ -166,8 +174,15 @@ NOTE: This file is imported from the following contexts, so be aware when writin recreate the publish layout, but under a TFM- or RID-specific root path. Because we're globbing from the PublishDir, the MSBuild Items will have the RecursiveDir metadata - this is used by the PackLogic to combine with the PackagePath we set below to ensure we have the correct layout in the end. If the PackLogic didn't try to use RecursiveDir, then - we could just explicitly set everything ourselves. --> + we could just explicitly set everything ourselves. + + We _also_ have to filter out apphosts here from platform-agnostic builds, because we don't want to include them in the tool package. + This is because we try not to influence the selection of UseAppHost (so that we do not impact 'normal' publishing and end up + influencing the contents of the 'normal' publish directory), so it's possible that the 'publish' of an otherwise RID-agnostic + tool may include an apphost. + --> <_PublishFiles Condition="'$(_ToolPackageShouldIncludeImplementation)' == 'true'" Include="$(PublishDir)/**/*" /> + <_PublishFiles Condition="'$(UseAppHost)' == 'true' and '$(RuntimeIdentifier)' == ''" Remove="$(PublishDir)$(AssemblyName)$(_NativeExecutableExtension)"/> @@ -195,11 +210,6 @@ NOTE: This file is imported from the following contexts, so be aware when writin <_GenerateToolsSettingsFileCacheFile>$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(_GenerateToolsSettingsFileCacheFile))) - - dotnet - executable - - <_ToolPackageRuntimeIdentifier Include="$(_UserSpecifiedToolPackageRids)" /> diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets index 0e991e2df7f9..7bb069dbc417 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets @@ -184,7 +184,7 @@ Copyright (c) .NET Foundation. All rights reserved. $([MSBuild]::VersionLessThan($(_TargetFrameworkVersionWithoutV), '8.0'))">true false - <_RuntimeIdentifierUsesAppHost Condition="$(RuntimeIdentifier.StartsWith('ios')) or $(RuntimeIdentifier.StartsWith('tvos')) or $(RuntimeIdentifier.StartsWith('maccatalyst')) or $(RuntimeIdentifier.StartsWith('android')) or $(RuntimeIdentifier.StartsWith('browser')) or $(RuntimeIdentifier.StartsWith('wasi'))">false + <_RuntimeIdentifierUsesAppHost Condition="$(RuntimeIdentifier.StartsWith('ios')) or $(RuntimeIdentifier.StartsWith('tvos')) or $(RuntimeIdentifier.StartsWith('maccatalyst')) or $(RuntimeIdentifier.StartsWith('android')) or $(RuntimeIdentifier.StartsWith('browser')) or $(RuntimeIdentifier.StartsWith('wasi')) or $(RuntimeIdentifier) == 'any'">false <_RuntimeIdentifierUsesAppHost Condition="'$(_IsPublishing)' == 'true' and '$(PublishAot)' == 'true'">false <_RuntimeIdentifierUsesAppHost Condition="'$(_RuntimeIdentifierUsesAppHost)' == ''">true { @@ -39,7 +40,7 @@ private string SetupNuGetPackage(bool multiTarget, string packageType = null, [C var packCommand = new PackCommand(helloWorldAsset); - var result = packCommand.Execute(); + var result = packCommand.Execute($"/bl:{id}-{{}}.binlog"); result.Should().Pass(); return packCommand.GetNuGetPackage(); @@ -192,9 +193,9 @@ public void It_does_not_contain_apphost_exe(bool multiTarget) string[] args = multiTarget ? new[] { $"/p:TargetFramework={_targetFrameworkOrFrameworks}" } : Array.Empty(); getValuesCommand.Execute(args) .Should().Pass(); - string runCommandPath = getValuesCommand.GetValues().Single(); - runCommandPath - .Should().Be("dotnet", because: "The RunCommand should recognize that this is a non-AppHost tool and should use the muxer to launch it"); + var runCommand = new FileInfo(getValuesCommand.GetValues().Single()); + runCommand.Name + .Should().Be("consoledemo" + Constants.ExeSuffix, because: "The RunCommand should recognize that this is an AppHost-using project and should use the AppHost for non-tool use cases."); } }