Skip to content

Commit

Permalink
Fix bootstrapper task not running when targeting win-* RIDs on non-…
Browse files Browse the repository at this point in the history
…Windows host platforms (#45)
  • Loading branch information
Tyrrrz committed Apr 27, 2024
1 parent 753d99d commit 5e1c494
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
16 changes: 16 additions & 0 deletions DotnetRuntimeBootstrapper/BootstrapperTask.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using DotnetRuntimeBootstrapper.Utils.Extensions;
using Microsoft.Build.Framework;
Expand All @@ -15,6 +16,13 @@ public class BootstrapperTask : Task
{
private Version Version { get; } = Assembly.GetExecutingAssembly().GetName().Version;

public string? RuntimeIdentifier { get; init; }

public bool IsWindowsTarget =>
string.IsNullOrWhiteSpace(RuntimeIdentifier)
&& RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|| RuntimeIdentifier?.StartsWith("win", StringComparison.OrdinalIgnoreCase) == true;

[Required]
public required string Variant { get; init; }

Expand Down Expand Up @@ -130,10 +138,18 @@ private void InjectResources()
public override bool Execute()
{
Log.LogMessage("Version: '{0}'.", Version);
Log.LogMessage("Runtime identifier: '{0}'.", RuntimeIdentifier);
Log.LogMessage("Variant: '{0}'.", Variant);
Log.LogMessage("Prompt required: '{0}'.", IsPromptRequired);
Log.LogMessage("Target: '{0}'.", TargetFilePath);

// Currently only Windows is supported
if (!IsWindowsTarget)
{
Log.LogMessage("Target platform is not Windows. Boostrapper will not be created.");
return true;
}

ExtractAppHost();
InjectConfiguration();
InjectResources();
Expand Down
23 changes: 6 additions & 17 deletions DotnetRuntimeBootstrapper/DotnetRuntimeBootstrapper.targets
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

<Target Name="CheckBootstrapperPrerequisites" BeforeTargets="CreateBootstrapperAfterBuild;CreateBootstrapperAfterPublish">
<!-- Warning: not .NET Core -->
<Warning
Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'"
Code="DRB_NOT_NETCORE"
Text="Project is not targeting .NET Core. Bootstrapper will not be created." />

<!-- Warning: not Windows target platform -->
<Warning
Condition="!$([MSBuild]::IsOsPlatform('Windows'))"
Code="DRB_NOT_WINDOWS"
Text="Target platform is not Windows. Boostrapper will not be created." />
</Target>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" TreatAsLocalProperty="IsNetCoreApp;IsWindowsTarget;CanGenerateBootstrapper">

<!-- Bootstrapper on build -->
<Target
Condition="$(GenerateBootstrapperOnBuild) AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::IsOsPlatform('Windows'))"
Condition="$(GenerateBootstrapperOnBuild)"
Name="CreateBootstrapperAfterBuild"
AfterTargets="Build">
<PropertyGroup>
Expand All @@ -26,13 +13,14 @@
</PropertyGroup>

<BootstrapperTask
RuntimeIdentifier="$(RuntimeIdentifier)"
Variant="$(BootstrapperVariant)"
IsPromptRequired="$(BootstrapperPromptRequired)"
TargetFilePath="$(TargetPath)" />
</Target>

<!-- Bootstrapper on publish -->
<Target
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::IsOsPlatform('Windows'))"
Name="CreateBootstrapperAfterPublish"
AfterTargets="Publish">
<PropertyGroup>
Expand All @@ -43,6 +31,7 @@
</PropertyGroup>

<BootstrapperTask
RuntimeIdentifier="$(RuntimeIdentifier)"
Variant="$(BootstrapperVariant)"
IsPromptRequired="$(BootstrapperPromptRequired)"
TargetFilePath="$([System.IO.Path]::Combine('$(ProjectDir)', '$(PublishDir)/$(AssemblyName).dll'))" />
Expand Down

0 comments on commit 5e1c494

Please sign in to comment.