Skip to content

Commit b68b27d

Browse files
committed
Fix apphost inclusion in the RID-agnostic tool packages.
1 parent 700a921 commit b68b27d

File tree

3 files changed

+78
-72
lines changed

3 files changed

+78
-72
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Copyright (c) .NET Foundation. All rights reserved.
3030
<PublishTrimmed Condition="'$(RuntimeIdentifier)' == ''">false</PublishTrimmed>
3131
<PublishReadyToRun Condition="'$(RuntimeIdentifier)' == ''">false</PublishReadyToRun>
3232
<PublishAot Condition="'$(RuntimeIdentifier)' == ''">false</PublishAot>
33+
34+
<!-- we want to ensure that we don't publish any AppHosts for the 'outer', RID-agnostic builds -->
35+
<UseAppHost Condition="'$(RuntimeIdentifier)' == ''">false</UseAppHost>
36+
3337
<!-- If shims are included, we need to make sure we restore for those RIDs so the apphost shims are available during restore/publish -->
3438
<_ToolRidsAreOnlyShims>false</_ToolRidsAreOnlyShims>
3539
<_ToolRidsAreOnlyShims Condition="'$(RuntimeIdentifiers)' == '' and $(PackAsToolShimRuntimeIdentifiers) != '' ">true</_ToolRidsAreOnlyShims>

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

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,74 +1110,6 @@ Copyright (c) .NET Foundation. All rights reserved.
11101110
</ItemGroup>
11111111
</Target>
11121112

1113-
<!--
1114-
============================================================
1115-
Run Information
1116-
The ProcessStart information that can be used to run this project.
1117-
============================================================
1118-
-->
1119-
1120-
<!-- TODO: can we now move all of this into the ComputeRunArguments target, or must this be kept for compat? -->
1121-
<PropertyGroup>
1122-
<RunWorkingDirectory Condition="'$(RunWorkingDirectory)' == ''">$(StartWorkingDirectory)</RunWorkingDirectory>
1123-
</PropertyGroup>
1124-
1125-
<Choose>
1126-
<When Condition="'$(StartAction)' == 'Program'">
1127-
<PropertyGroup>
1128-
<RunCommand Condition="'$(RunCommand)' == ''">$(StartProgram)</RunCommand>
1129-
<RunArguments Condition="'$(RunArguments)' == ''">$(StartArguments)</RunArguments>
1130-
</PropertyGroup>
1131-
</When>
1132-
1133-
<When Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_IsExecutable)' == 'true'">
1134-
<PropertyGroup Condition="'$(UseAppHost)' != 'true'">
1135-
<!-- TODO: https://github.com/dotnet/sdk/issues/20 Need to get the DotNetHost path from MSBuild -->
1136-
<RunCommand Condition="'$(RunCommand)' == ''">dotnet</RunCommand>
1137-
1138-
<_NetCoreRunArguments>exec &quot;$(TargetPath)&quot;</_NetCoreRunArguments>
1139-
<RunArguments Condition="'$(RunArguments)' == '' and '$(StartArguments)' != ''">$(_NetCoreRunArguments) $(StartArguments)</RunArguments>
1140-
<RunArguments Condition="'$(RunArguments)' == ''">$(_NetCoreRunArguments)</RunArguments>
1141-
</PropertyGroup>
1142-
1143-
<PropertyGroup Condition="'$(UseAppHost)' == 'true'">
1144-
<RunCommand Condition="'$(RunCommand)' == ''">$(TargetDir)$(AssemblyName)$(_NativeExecutableExtension)</RunCommand>
1145-
<RunArguments Condition="'$(RunArguments)' == ''">$(StartArguments)</RunArguments>
1146-
</PropertyGroup>
1147-
</When>
1148-
1149-
<When Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(_IsExecutable)' == 'true'">
1150-
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform(`Windows`))">
1151-
<RunCommand Condition="'$(RunCommand)' == ''">$(TargetPath)</RunCommand>
1152-
<RunArguments Condition="'$(RunArguments)' == ''">$(StartArguments)</RunArguments>
1153-
</PropertyGroup>
1154-
<PropertyGroup Condition="$([MSBuild]::IsOSUnixLike())">
1155-
<RunCommand Condition="'$(RunCommand)' == ''">mono</RunCommand>
1156-
<RunArguments Condition="'$(RunArguments)' == ''">&quot;$(TargetPath)&quot; $(StartArguments)</RunArguments>
1157-
</PropertyGroup>
1158-
</When>
1159-
</Choose>
1160-
1161-
<PropertyGroup>
1162-
<!-- Ensure $(RunWorkingDirectory) is a full path -->
1163-
<RunWorkingDirectory Condition="'$(RunWorkingDirectory)' != '' and '$([System.IO.Path]::IsPathRooted($(RunWorkingDirectory)))' != 'true'">$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(RunWorkingDirectory)'))))</RunWorkingDirectory>
1164-
</PropertyGroup>
1165-
1166-
<ItemGroup>
1167-
<!-- Signals that this project supports the target-based run invocation protocol powered by the ComputeRunArguments target. -->
1168-
<ProjectCapability Include="SupportsComputeRunCommand" />
1169-
</ItemGroup>
1170-
<!-- Placeholder target for tools to override RunCommand/RunArguments/RunWorkingDirectory.
1171-
This allows tools to run validation or logic required to compute any required data,
1172-
which cannot be done during evaluation. -->
1173-
<Target Name="ComputeRunArguments" />
1174-
1175-
1176-
<!-- Override MSBuild Run Target -->
1177-
<Target Name="Run" DependsOnTargets="ComputeRunArguments">
1178-
<Exec Command="$(RunCommand) $(RunArguments)" WorkingDirectory="$(RunWorkingDirectory)"/>
1179-
</Target>
1180-
11811113
<!--
11821114
============================================================
11831115
CoreGenerateSatelliteAssemblies
@@ -1443,6 +1375,78 @@ Copyright (c) .NET Foundation. All rights reserved.
14431375
<Import Project="$(ILLinkTargetsPath)" Condition="'$(ILLinkTargetsPath)' != '' and '$(Language)' != 'C++'" />
14441376
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.Analyzers.targets" Condition="'$(Language)' == 'C#' or '$(Language)' == 'VB'" />
14451377

1378+
<!--
1379+
============================================================
1380+
Run Information
1381+
The ProcessStart information that can be used to run this project.
1382+
============================================================
1383+
-->
1384+
1385+
<!-- TODO: can we now move all of this into the ComputeRunArguments target, or must this be kept for compat? -->
1386+
<!-- NOTE: the targets above may change UseAppHost and other relevant properties, and so all of this pre-computation needs to come after it.
1387+
I checked this when I moved it and none of those targets _used_ the Run* properties.
1388+
This is yet another case where precomputing data during evaluation _is bad_ and should be moved to a Target. -->
1389+
1390+
<PropertyGroup>
1391+
<RunWorkingDirectory Condition="'$(RunWorkingDirectory)' == ''">$(StartWorkingDirectory)</RunWorkingDirectory>
1392+
</PropertyGroup>
1393+
1394+
<Choose>
1395+
<When Condition="'$(StartAction)' == 'Program'">
1396+
<PropertyGroup>
1397+
<RunCommand Condition="'$(RunCommand)' == ''">$(StartProgram)</RunCommand>
1398+
<RunArguments Condition="'$(RunArguments)' == ''">$(StartArguments)</RunArguments>
1399+
</PropertyGroup>
1400+
</When>
1401+
1402+
<When Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_IsExecutable)' == 'true'">
1403+
<PropertyGroup Condition="'$(UseAppHost)' != 'true'">
1404+
<!-- TODO: https://github.com/dotnet/sdk/issues/20 Need to get the DotNetHost path from MSBuild -->
1405+
<RunCommand Condition="'$(RunCommand)' == ''">dotnet</RunCommand>
1406+
1407+
<_NetCoreRunArguments>exec &quot;$(TargetPath)&quot;</_NetCoreRunArguments>
1408+
<RunArguments Condition="'$(RunArguments)' == '' and '$(StartArguments)' != ''">$(_NetCoreRunArguments) $(StartArguments)</RunArguments>
1409+
<RunArguments Condition="'$(RunArguments)' == ''">$(_NetCoreRunArguments)</RunArguments>
1410+
</PropertyGroup>
1411+
1412+
<PropertyGroup Condition="'$(UseAppHost)' == 'true'">
1413+
<RunCommand Condition="'$(RunCommand)' == ''">$(TargetDir)$(AssemblyName)$(_NativeExecutableExtension)</RunCommand>
1414+
<RunArguments Condition="'$(RunArguments)' == ''">$(StartArguments)</RunArguments>
1415+
</PropertyGroup>
1416+
</When>
1417+
1418+
<When Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(_IsExecutable)' == 'true'">
1419+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform(`Windows`))">
1420+
<RunCommand Condition="'$(RunCommand)' == ''">$(TargetPath)</RunCommand>
1421+
<RunArguments Condition="'$(RunArguments)' == ''">$(StartArguments)</RunArguments>
1422+
</PropertyGroup>
1423+
<PropertyGroup Condition="$([MSBuild]::IsOSUnixLike())">
1424+
<RunCommand Condition="'$(RunCommand)' == ''">mono</RunCommand>
1425+
<RunArguments Condition="'$(RunArguments)' == ''">&quot;$(TargetPath)&quot; $(StartArguments)</RunArguments>
1426+
</PropertyGroup>
1427+
</When>
1428+
</Choose>
1429+
1430+
<PropertyGroup>
1431+
<!-- Ensure $(RunWorkingDirectory) is a full path -->
1432+
<RunWorkingDirectory Condition="'$(RunWorkingDirectory)' != '' and '$([System.IO.Path]::IsPathRooted($(RunWorkingDirectory)))' != 'true'">$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(RunWorkingDirectory)'))))</RunWorkingDirectory>
1433+
</PropertyGroup>
1434+
1435+
<ItemGroup>
1436+
<!-- Signals that this project supports the target-based run invocation protocol powered by the ComputeRunArguments target. -->
1437+
<ProjectCapability Include="SupportsComputeRunCommand" />
1438+
</ItemGroup>
1439+
<!-- Placeholder target for tools to override RunCommand/RunArguments/RunWorkingDirectory.
1440+
This allows tools to run validation or logic required to compute any required data,
1441+
which cannot be done during evaluation. -->
1442+
<Target Name="ComputeRunArguments" />
1443+
1444+
1445+
<!-- Override MSBuild Run Target -->
1446+
<Target Name="Run" DependsOnTargets="ComputeRunArguments">
1447+
<Exec Command="$(RunCommand) $(RunArguments)" WorkingDirectory="$(RunWorkingDirectory)"/>
1448+
</Target>
1449+
14461450
<!-- Import WindowsDesktop targets if necessary -->
14471451
<PropertyGroup Condition=" '$(ImportWindowsDesktopTargets)' == ''
14481452
and ('$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true') ">

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,8 @@ public void It_does_not_contain_apphost_exe(bool multiTarget)
193193
getValuesCommand.Execute(args)
194194
.Should().Pass();
195195
string runCommandPath = getValuesCommand.GetValues().Single();
196-
Path.GetExtension(runCommandPath)
197-
.Should().Be(extension);
198-
File.Exists(runCommandPath).Should()
199-
.BeTrue("run command should be apphost executable (for WinExe) to debug. But it will not be packed");
196+
runCommandPath
197+
.Should().Be("dotnet", because: "The RunCommand should recognize that this is a non-AppHost tool and should use the muxer to launch it");
200198
}
201199
}
202200

0 commit comments

Comments
 (0)