Skip to content

Commit 3b7b36b

Browse files
author
William Li
committed
Need apphost in build but do not pack it
1 parent 527e0e0 commit 3b7b36b

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/ResolveToolPackagePaths.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.IO;
67
using System.Linq;
@@ -16,6 +17,8 @@ namespace Microsoft.NET.Build.Tasks
1617
/// </summary>
1718
public sealed class ResolveToolPackagePaths : TaskBase
1819
{
20+
public string AppHostIntermediatePath { get; set; }
21+
1922
[Required]
2023
public ITaskItem[] ResolvedFileToPublish { get; set; }
2124

@@ -36,6 +39,12 @@ protected override void ExecuteCore()
3639
var result = new List<TaskItem>();
3740
foreach (ITaskItem r in ResolvedFileToPublish)
3841
{
42+
// skip packing apphost since a dotnet tool will get a generated shim executable once installed
43+
if (r.ItemSpec.Equals(AppHostIntermediatePath, StringComparison.Ordinal))
44+
{
45+
continue;
46+
}
47+
3948
string relativePath = r.GetMetadata("RelativePath");
4049
var fullpath = Path.GetFullPath(
4150
Path.Combine(PublishDir,

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Copyright (c) .NET Foundation. All rights reserved.
3737
</ItemGroup>
3838

3939
<ResolveToolPackagePaths
40+
AppHostIntermediatePath="$(AppHostIntermediatePath)"
4041
ResolvedFileToPublish="@(ResolvedFileToPublish)"
4142
PublishDir="$(PublishDir)"
4243
TargetFramework="$(TargetFramework)">

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ Copyright (c) .NET Foundation. All rights reserved.
104104
<SelfContained Condition="'$(SelfContained)' == '' and '$(RuntimeIdentifier)' != ''">true</SelfContained>
105105
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
106106
<UseAppHost Condition="'$(UseAppHost)' == '' and
107-
('$(SelfContained)' == 'true' or '$(PackAsTool)' != 'true') and
108107
('$(SelfContained)' == 'true' or
109108
('$(RuntimeIdentifier)' != '' and '$(_TargetFrameworkVersionWithoutV)' >= '2.1') or
110109
'$(_TargetFrameworkVersionWithoutV)' >= '3.0')">true</UseAppHost>

src/Tests/Microsoft.NET.ToolPack.Tests/GivenThatWeWantToPackAToolProject.cs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.Runtime.CompilerServices;
1616
using System;
1717
using System.Runtime.InteropServices;
18+
using Microsoft.DotNet.PlatformAbstractions;
1819

1920
namespace Microsoft.NET.ToolPack.Tests
2021
{
@@ -125,10 +126,10 @@ public void It_contains_runtimeconfig_for_each_tfm(bool multiTarget)
125126
}
126127
}
127128

128-
[Theory]
129+
[WindowsOnlyTheory]
129130
[InlineData(true)]
130131
[InlineData(false)]
131-
public void It_does_not_contain_apphost_exe(bool multiTarget)
132+
public void Given_Windows_It_does_not_contain_apphost_exe_but_RunCommand_is_apphost_exe(bool multiTarget)
132133
{
133134
_targetFrameworkOrFrameworks = "netcoreapp3.0";
134135

@@ -140,7 +141,7 @@ public void It_does_not_contain_apphost_exe(bool multiTarget)
140141

141142
foreach (NuGet.Frameworks.NuGetFramework framework in supportedFrameworks)
142143
{
143-
var extension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "";
144+
var extension =".exe";
144145
var allItems = nupkgReader.GetToolItems().SelectMany(i => i.Items).ToList();
145146
allItems.Should().NotContain($"tools/{framework.GetShortFolderName()}/any/consoledemo{extension}");
146147
}
@@ -154,8 +155,45 @@ public void It_does_not_contain_apphost_exe(bool multiTarget)
154155
GetValuesCommand.ValueType.Property);
155156

156157
getValuesCommand.Execute();
157-
Path.GetExtension(getValuesCommand.GetValues().Single())
158-
.Should().NotBe(".exe", "Repro https://github.com/dotnet/cli/issues/11299");
158+
string runCommandPath = getValuesCommand.GetValues().Single();
159+
Path.GetExtension(runCommandPath)
160+
.Should().Be(".exe");
161+
File.Exists(runCommandPath).Should()
162+
.BeTrue("run command should be apphost exe for WinExe to debug. But it will not be packed");
163+
}
164+
165+
[PlatformSpecificTheory(Platform.Linux, Platform.Darwin, Platform.FreeBSD)]
166+
[InlineData(true)]
167+
[InlineData(false)]
168+
public void Given_nonwindows_It_does_not_contain_apphost_and_RunCommand_is_not_apphost(bool multiTarget)
169+
{
170+
_targetFrameworkOrFrameworks = "netcoreapp3.0";
171+
172+
var nugetPackage = SetupNuGetPackage(multiTarget);
173+
using (var nupkgReader = new PackageArchiveReader(nugetPackage))
174+
{
175+
IEnumerable<NuGet.Frameworks.NuGetFramework> supportedFrameworks = nupkgReader.GetSupportedFrameworks();
176+
supportedFrameworks.Should().NotBeEmpty();
177+
178+
foreach (NuGet.Frameworks.NuGetFramework framework in supportedFrameworks)
179+
{
180+
var allItems = nupkgReader.GetToolItems().SelectMany(i => i.Items).ToList();
181+
allItems.Should().NotContain($"tools/{framework.GetShortFolderName()}/any/consoledemo");
182+
}
183+
}
184+
185+
var getValuesCommand = new GetValuesCommand(
186+
Log,
187+
_testRoot,
188+
_targetFrameworkOrFrameworks,
189+
"RunCommand",
190+
GetValuesCommand.ValueType.Property);
191+
192+
getValuesCommand.Execute();
193+
string runCommandPath = getValuesCommand.GetValues().Single();
194+
Path.GetExtension(runCommandPath)
195+
.Should().NotBe(".exe");
196+
File.Exists(runCommandPath).Should().BeTrue("non Windows does not generate apphost by default");
159197
}
160198

161199
[Theory]

0 commit comments

Comments
 (0)