diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs index 8d7bb98d39b6..1e248c9cf639 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs @@ -5,6 +5,8 @@ using Microsoft.NET.HostModel.Bundle; using System; using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; namespace Microsoft.NET.Build.Tasks { @@ -17,14 +19,27 @@ public class GenerateBundle : TaskBase [Required] public bool IncludeSymbols { get; set; } [Required] + public string TargetFrameworkVersion { get; set; } + [Required] + public string RuntimeIdentifier { get; set; } + [Required] public string OutputDir { get; set; } [Required] public bool ShowDiagnosticOutput { get; set; } + [Output] + public ITaskItem[] ExcludedFiles { get; set; } + protected override void ExecuteCore() { - BundleOptions options = BundleOptions.BundleAllContent | (IncludeSymbols ? BundleOptions.BundleSymbolFiles : BundleOptions.None); - var bundler = new Bundler(AppHostName, OutputDir, options, diagnosticOutput: ShowDiagnosticOutput); + OSPlatform targetOS = RuntimeIdentifier.StartsWith("win") ? OSPlatform.Windows : + RuntimeIdentifier.StartsWith("osx") ? OSPlatform.OSX : OSPlatform.Linux; + + BundleOptions options = BundleOptions.BundleAllContent; + options |= IncludeSymbols ? BundleOptions.BundleSymbolFiles : BundleOptions.None; + + var bundler = new Bundler(AppHostName, OutputDir, options, targetOS, new Version(TargetFrameworkVersion), ShowDiagnosticOutput); + var fileSpec = new List(FilesToBundle.Length); foreach (var item in FilesToBundle) @@ -34,6 +49,14 @@ protected override void ExecuteCore() } bundler.GenerateBundle(fileSpec); + + // Certain files are excluded from the bundle, based on BundleOptions. + // For example: + // Native files and contents files are excluded by default. + // hostfxr and hostpolicy are excluded until singlefilehost is available. + // Return the set of excluded files in ExcludedFiles, so that they can be placed in the publish directory. + + ExcludedFiles = FilesToBundle.Zip(fileSpec, (item, spec) => (spec.Excluded) ? item : null).Where(x => x != null).ToArray(); } } } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets index 43f38fc8e03b..849c3cb062db 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets @@ -947,9 +947,7 @@ Copyright (c) .NET Foundation. All rights reserved. - - @@ -959,12 +957,26 @@ Copyright (c) .NET Foundation. All rights reserved. Inputs="@(_FilesToBundle)" Outputs="$(PublishedSingleFilePath)"> + + false + false + + - + ShowDiagnosticOutput="$(TraceSingleFileBundler)"> + + + + + + + +