Skip to content

Commit 5e1c494

Browse files
authored
Fix bootstrapper task not running when targeting win-* RIDs on non-Windows host platforms (#45)
1 parent 753d99d commit 5e1c494

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

DotnetRuntimeBootstrapper/BootstrapperTask.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Reflection;
4+
using System.Runtime.InteropServices;
45
using System.Text;
56
using DotnetRuntimeBootstrapper.Utils.Extensions;
67
using Microsoft.Build.Framework;
@@ -15,6 +16,13 @@ public class BootstrapperTask : Task
1516
{
1617
private Version Version { get; } = Assembly.GetExecutingAssembly().GetName().Version;
1718

19+
public string? RuntimeIdentifier { get; init; }
20+
21+
public bool IsWindowsTarget =>
22+
string.IsNullOrWhiteSpace(RuntimeIdentifier)
23+
&& RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
24+
|| RuntimeIdentifier?.StartsWith("win", StringComparison.OrdinalIgnoreCase) == true;
25+
1826
[Required]
1927
public required string Variant { get; init; }
2028

@@ -130,10 +138,18 @@ private void InjectResources()
130138
public override bool Execute()
131139
{
132140
Log.LogMessage("Version: '{0}'.", Version);
141+
Log.LogMessage("Runtime identifier: '{0}'.", RuntimeIdentifier);
133142
Log.LogMessage("Variant: '{0}'.", Variant);
134143
Log.LogMessage("Prompt required: '{0}'.", IsPromptRequired);
135144
Log.LogMessage("Target: '{0}'.", TargetFilePath);
136145

146+
// Currently only Windows is supported
147+
if (!IsWindowsTarget)
148+
{
149+
Log.LogMessage("Target platform is not Windows. Boostrapper will not be created.");
150+
return true;
151+
}
152+
137153
ExtractAppHost();
138154
InjectConfiguration();
139155
InjectResources();

DotnetRuntimeBootstrapper/DotnetRuntimeBootstrapper.targets

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
2-
3-
<Target Name="CheckBootstrapperPrerequisites" BeforeTargets="CreateBootstrapperAfterBuild;CreateBootstrapperAfterPublish">
4-
<!-- Warning: not .NET Core -->
5-
<Warning
6-
Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'"
7-
Code="DRB_NOT_NETCORE"
8-
Text="Project is not targeting .NET Core. Bootstrapper will not be created." />
9-
10-
<!-- Warning: not Windows target platform -->
11-
<Warning
12-
Condition="!$([MSBuild]::IsOsPlatform('Windows'))"
13-
Code="DRB_NOT_WINDOWS"
14-
Text="Target platform is not Windows. Boostrapper will not be created." />
15-
</Target>
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" TreatAsLocalProperty="IsNetCoreApp;IsWindowsTarget;CanGenerateBootstrapper">
162

3+
<!-- Bootstrapper on build -->
174
<Target
18-
Condition="$(GenerateBootstrapperOnBuild) AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::IsOsPlatform('Windows'))"
5+
Condition="$(GenerateBootstrapperOnBuild)"
196
Name="CreateBootstrapperAfterBuild"
207
AfterTargets="Build">
218
<PropertyGroup>
@@ -26,13 +13,14 @@
2613
</PropertyGroup>
2714

2815
<BootstrapperTask
16+
RuntimeIdentifier="$(RuntimeIdentifier)"
2917
Variant="$(BootstrapperVariant)"
3018
IsPromptRequired="$(BootstrapperPromptRequired)"
3119
TargetFilePath="$(TargetPath)" />
3220
</Target>
3321

22+
<!-- Bootstrapper on publish -->
3423
<Target
35-
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::IsOsPlatform('Windows'))"
3624
Name="CreateBootstrapperAfterPublish"
3725
AfterTargets="Publish">
3826
<PropertyGroup>
@@ -43,6 +31,7 @@
4331
</PropertyGroup>
4432

4533
<BootstrapperTask
34+
RuntimeIdentifier="$(RuntimeIdentifier)"
4635
Variant="$(BootstrapperVariant)"
4736
IsPromptRequired="$(BootstrapperPromptRequired)"
4837
TargetFilePath="$([System.IO.Path]::Combine('$(ProjectDir)', '$(PublishDir)/$(AssemblyName).dll'))" />

0 commit comments

Comments
 (0)