Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bootstrapper task not running when targeting win-* RIDs on non-Windows host platforms #45

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading