diff --git a/global.json b/global.json index 6b5cc3949eea..20352cc786aa 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "tools": { - "dotnet": "5.0.100-preview.6.20266.3", + "dotnet": "5.0.100-preview.6.20280.6", "runtimes": { "dotnet": [ "$(MicrosoftNETCoreAppRuntimePackageVersion)" diff --git a/src/Assets/TestProjects/HelloWorldWithSubDirs/HelloWorldWithSubDirs.csproj b/src/Assets/TestProjects/HelloWorldWithSubDirs/HelloWorldWithSubDirs.csproj index d24ba764b014..1289db290c53 100644 --- a/src/Assets/TestProjects/HelloWorldWithSubDirs/HelloWorldWithSubDirs.csproj +++ b/src/Assets/TestProjects/HelloWorldWithSubDirs/HelloWorldWithSubDirs.csproj @@ -2,18 +2,18 @@ Exe - netcoreapp3.0 + net5.0 PreserveNewest - + PreserveNewest $(ExcludeNewest) - + Always $(ExcludeAlways) diff --git a/src/Tasks/Common/MetadataKeys.cs b/src/Tasks/Common/MetadataKeys.cs index a3db5b6dee17..45482532dfff 100644 --- a/src/Tasks/Common/MetadataKeys.cs +++ b/src/Tasks/Common/MetadataKeys.cs @@ -80,6 +80,9 @@ internal static class MetadataKeys // Targeting packs public const string PackageConflictPreferredPackages = "PackageConflictPreferredPackages"; + // Runtime packs + public const string DropFromSingleFile = "DropFromSingleFile"; + // Content files public const string PPOutputPath = "PPOutputPath"; public const string CodeLanguage = "CodeLanguage"; diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs index 1e248c9cf639..7b68b6aa22af 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs @@ -19,6 +19,10 @@ public class GenerateBundle : TaskBase [Required] public bool IncludeSymbols { get; set; } [Required] + public bool IncludeNativeLibraries { get; set; } + [Required] + public bool IncludeAllContent { get; set; } + [Required] public string TargetFrameworkVersion { get; set; } [Required] public string RuntimeIdentifier { get; set; } @@ -35,7 +39,9 @@ protected override void ExecuteCore() OSPlatform targetOS = RuntimeIdentifier.StartsWith("win") ? OSPlatform.Windows : RuntimeIdentifier.StartsWith("osx") ? OSPlatform.OSX : OSPlatform.Linux; - BundleOptions options = BundleOptions.BundleAllContent; + BundleOptions options = BundleOptions.None; + options |= IncludeNativeLibraries ? BundleOptions.BundleNativeBinaries : BundleOptions.None; + options |= IncludeAllContent ? BundleOptions.BundleAllContent : BundleOptions.None; options |= IncludeSymbols ? BundleOptions.BundleSymbolFiles : BundleOptions.None; var bundler = new Bundler(AppHostName, OutputDir, options, targetOS, new Version(TargetFrameworkVersion), ShowDiagnosticOutput); diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs index 33ae4224f234..277fcb28532d 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs @@ -90,6 +90,8 @@ public class GenerateDepsFile : TaskBase public bool IsSelfContained { get; set; } + public bool IsSingleFile { get; set; } + public bool IncludeRuntimeFileVersions { get; set; } [Required] @@ -169,7 +171,10 @@ private void WriteDepsFile(string depsFilePath) SingleProjectInfo.CreateProjectReferenceInfos(ReferencePaths, ReferenceSatellitePaths, isUserRuntimeAssembly); IEnumerable runtimePackAssets = - IsSelfContained ? RuntimePackAssets.Select(item => RuntimePackAssetInfo.FromItem(item)) : Enumerable.Empty(); + IsSelfContained ? + RuntimePackAssets.Where(item => !IsSingleFile || !item.GetMetadata(MetadataKeys.DropFromSingleFile).Equals("true")) + .Select(item => RuntimePackAssetInfo.FromItem(item)) : + Enumerable.Empty(); DependencyContextBuilder builder; if (projectContext != null) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs index 69b54de2b737..7d803bff13fe 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs @@ -31,6 +31,9 @@ public class ResolveAppHosts : TaskBase [Required] public string DotNetAppHostExecutableNameWithoutExtension { get; set; } + [Required] + public string DotNetSingleFileHostExecutableNameWithoutExtension { get; set; } + /// /// The file name of comhost asset. /// @@ -57,6 +60,9 @@ public class ResolveAppHosts : TaskBase [Output] public ITaskItem[] AppHost { get; set; } + [Output] + public ITaskItem[] SingleFileHost { get; set; } + [Output] public ITaskItem[] ComHost { get; set; } @@ -107,6 +113,20 @@ protected override void ExecuteCore() AppHost = new ITaskItem[] { appHostItem }; } + var singlefileHostItem = GetHostItem( + AppHostRuntimeIdentifier, + knownAppHostPacksForTargetFramework, + packagesToDownload, + DotNetSingleFileHostExecutableNameWithoutExtension, + "SingleFileHost", + isExecutable: true, + errorIfNotFound: true); + + if (singlefileHostItem != null) + { + SingleFileHost = new ITaskItem[] { singlefileHostItem }; + } + var comHostItem = GetHostItem( AppHostRuntimeIdentifier, knownAppHostPacksForTargetFramework, diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs index 2b857d5b0d20..6d5baae5cd9e 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveRuntimePackAssets.cs @@ -143,6 +143,7 @@ private void AddRuntimePackAssetsFromManifest(List runtimePackAssets, assetItem.SetMetadata("AssemblyVersion", fileElement.Attribute("AssemblyVersion")?.Value); assetItem.SetMetadata("FileVersion", fileElement.Attribute("FileVersion")?.Value); assetItem.SetMetadata("PublicKeyToken", fileElement.Attribute("PublicKeyToken")?.Value); + assetItem.SetMetadata("DropFromSingleFile", fileElement.Attribute("DropFromSingleFile")?.Value); runtimePackAssets.Add(assetItem); } 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 849c3cb062db..b68351f46d52 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 @@ -547,6 +547,12 @@ Copyright (c) .NET Foundation. All rights reserved. shims/%(_EmbeddedApphostPaths.ShimRuntimeIdentifier)/%(_EmbeddedApphostPaths.Filename)%(_EmbeddedApphostPaths.Extension) PreserveNewest + + + <_FilesToDrop Include="@(ResolvedFileToPublish)" + Condition="'$(PublishSingleFile)' == 'true' and + '%(ResolvedFileToPublish.DropFromSingleFile)' == 'true'"/> + @@ -917,10 +923,12 @@ Copyright (c) .NET Foundation. All rights reserved. + <_TrimRuntimeAssets Condition="'$(PublishSingleFile)' == 'true' and '$(SelfContained)' == 'true'">true <_UseBuildDependencyFile Condition="'@(_ExcludeFromPublishPackageReference)' == '' and '@(RuntimeStorePackages)' == '' and '$(PreserveStoreLayout)' != 'true' and - '$(PublishTrimmed)' != 'true'">true + '$(PublishTrimmed)' != 'true' and + '$(_TrimRuntimeAssets)' != 'true'">true @@ -937,17 +945,17 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'$(PublishSingleFile)' == 'true'"> - <_FilesToBundle Include="@(ResolvedFileToPublish)" Condition="'%(ResolvedFileToPublish.ExcludeFromSingleFile)' != 'true'"/> + <_FilesToBundle Include="@(ResolvedFileToPublish)" + Condition="'%(ResolvedFileToPublish.ExcludeFromSingleFile)' != 'true'"/> + + $(AssemblyName)$(_NativeExecutableExtension) $(PublishDir)$(PublishedSingleFileName) - - - - + @@ -960,11 +968,15 @@ Copyright (c) .NET Foundation. All rights reserved. false false + false + false $(PublishDepsFilePath) $(IntermediateOutputPath)$(ProjectDepsFileName) - $(PublishDir)$(ProjectDepsFileName) + $(PublishDir)$(ProjectDepsFileName) + <_IsSingleFilePublish Condition="'$(PublishSingleFile)' == ''">false + <_IsSingleFilePublish Condition="'$(PublishSingleFile)' != ''">$(PublishSingleFile) @@ -1013,6 +1027,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_ResolvedNuGetFilesForPublish Include="@(ResourceCopyLocalItems)" Condition="'%(ResourceCopyLocalItems.CopyToPublishDirectory)' != 'false'" /> <_ResolvedNuGetFilesForPublish Include="@(RuntimeCopyLocalItems)" Condition="'%(RuntimeCopyLocalItems.CopyToPublishDirectory)' != 'false'" /> <_ResolvedNuGetFilesForPublish Remove="@(_PublishConflictPackageFiles)" Condition="'%(_PublishConflictPackageFiles.ConflictItemType)' != 'Reference'" /> + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index fe2f507440b7..164d06937a53 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -97,6 +97,7 @@ Copyright (c) .NET Foundation. All rights reserved. RuntimeFrameworkVersion="$(RuntimeFrameworkVersion)" PackAsToolShimRuntimeIdentifiers="@(_PackAsToolShimRuntimeIdentifiers)" DotNetAppHostExecutableNameWithoutExtension="$(_DotNetAppHostExecutableNameWithoutExtension)" + DotNetSingleFileHostExecutableNameWithoutExtension="$(_DotNetSingleFileHostExecutableNameWithoutExtension)" DotNetComHostLibraryNameWithoutExtension="$(_DotNetComHostLibraryNameWithoutExtension)" DotNetIjwHostLibraryNameWithoutExtension="$(_DotNetIjwHostLibraryNameWithoutExtension)" RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)" @@ -104,6 +105,7 @@ Copyright (c) .NET Foundation. All rights reserved. + @@ -187,6 +189,14 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + + + @@ -234,6 +244,16 @@ Copyright (c) .NET Foundation. All rights reserved. @(ResolvedAppHostPack->'%(Path)') + + + %(ResolvedSingleFileHostPack.PackageDirectory)\%(ResolvedSingleFileHostPack.PathInPackage) + + + + + @(ResolvedSingleFileHostPack->'%(Path)') + + %(ResolvedComHostPack.PackageDirectory)\%(ResolvedComHostPack.PathInPackage) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 17ac5957a65e..1025cdd52a79 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -83,6 +83,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_DotNetAppHostExecutableNameWithoutExtension>apphost <_DotNetAppHostExecutableName>$(_DotNetAppHostExecutableNameWithoutExtension)$(_NativeExecutableExtension) + <_DotNetSingleFileHostExecutableNameWithoutExtension>singlefilehost <_DotNetComHostLibraryNameWithoutExtension>comhost <_DotNetComHostLibraryName>$(_DotNetComHostLibraryNameWithoutExtension)$(_ComHostLibraryExtension) <_DotNetIjwHostLibraryNameWithoutExtension>Ijwhost @@ -415,7 +416,7 @@ Copyright (c) .NET Foundation. All rights reserved. + + $(SingleFileHostSourcePath) + + +