Add back in copying of RuntimeAssets during publish.
Any NuGet packages that had contentFiles weren't getting the content files added to the published output directory. This breaks things like debugging in VS Code. Fix #2459
This commit is contained in:
parent
9d71cce383
commit
aeaf8f0380
1 changed files with 37 additions and 57 deletions
|
@ -1,21 +1,20 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
|
||||||
using Microsoft.DotNet.ProjectModel;
|
|
||||||
using Microsoft.DotNet.ProjectModel.Compilation;
|
|
||||||
using NuGet.Frameworks;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.DotNet.Cli.Compiler.Common;
|
using Microsoft.DotNet.Cli.Compiler.Common;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.Files;
|
using Microsoft.DotNet.Files;
|
||||||
using Microsoft.DotNet.Tools.Common;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.ProjectModel.Utilities;
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
using NuGet.Versioning;
|
using Microsoft.DotNet.ProjectModel.Utilities;
|
||||||
|
using Microsoft.DotNet.Tools.Common;
|
||||||
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
using NuGet.Frameworks;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Publish
|
namespace Microsoft.DotNet.Tools.Publish
|
||||||
{
|
{
|
||||||
|
@ -134,6 +133,10 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
.ToDictionary(e => e.Library.Identity.Name);
|
.ToDictionary(e => e.Library.Identity.Name);
|
||||||
var collectExclusionList = context.IsPortable ? GetExclusionList(context, packageExports) : new HashSet<string>();
|
var collectExclusionList = context.IsPortable ? GetExclusionList(context, packageExports) : new HashSet<string>();
|
||||||
|
|
||||||
|
// Get the output paths used by the call to `dotnet build` above (since we didn't pass `--output`, they will be different from
|
||||||
|
// our current output paths)
|
||||||
|
var buildOutputPaths = context.GetOutputPaths(configuration, buildBasePath);
|
||||||
|
|
||||||
var exports = exporter.GetAllExports();
|
var exports = exporter.GetAllExports();
|
||||||
foreach (var export in exports.Where(e => !collectExclusionList.Contains(e.Library.Identity.Name)))
|
foreach (var export in exports.Where(e => !collectExclusionList.Contains(e.Library.Identity.Name)))
|
||||||
{
|
{
|
||||||
|
@ -141,6 +144,19 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
|
|
||||||
PublishAssetGroups(export.RuntimeAssemblyGroups, outputPath, nativeSubdirectories: false, includeRuntimeGroups: context.IsPortable);
|
PublishAssetGroups(export.RuntimeAssemblyGroups, outputPath, nativeSubdirectories: false, includeRuntimeGroups: context.IsPortable);
|
||||||
PublishAssetGroups(export.NativeLibraryGroups, outputPath, nativeSubdirectories, includeRuntimeGroups: context.IsPortable);
|
PublishAssetGroups(export.NativeLibraryGroups, outputPath, nativeSubdirectories, includeRuntimeGroups: context.IsPortable);
|
||||||
|
|
||||||
|
var runtimeAssetsToCopy = export.RuntimeAssets.Where(a => ShouldCopyExportRuntimeAsset(context, buildOutputPaths, export, a));
|
||||||
|
runtimeAssetsToCopy.StructuredCopyTo(outputPath, outputPaths.IntermediateOutputDirectoryPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.ProjectFile.HasRuntimeOutput(configuration) && !context.TargetFramework.IsDesktop())
|
||||||
|
{
|
||||||
|
PublishFiles(
|
||||||
|
new[] {
|
||||||
|
buildOutputPaths.RuntimeFiles.DepsJson,
|
||||||
|
buildOutputPaths.RuntimeFiles.RuntimeConfigJson
|
||||||
|
},
|
||||||
|
outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.PreserveCompilationContext.GetValueOrDefault())
|
if (options.PreserveCompilationContext.GetValueOrDefault())
|
||||||
|
@ -151,9 +167,6 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildOutputPaths = context.GetOutputPaths(configuration, buildBasePath, null);
|
|
||||||
PublishBuildOutputFiles(buildOutputPaths, context, outputPath, Configuration);
|
|
||||||
|
|
||||||
var contentFiles = new ContentFiles(context);
|
var contentFiles = new ContentFiles(context);
|
||||||
contentFiles.StructuredCopyTo(outputPath);
|
contentFiles.StructuredCopyTo(outputPath);
|
||||||
|
|
||||||
|
@ -171,59 +184,26 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PublishBuildOutputFiles(OutputPaths buildOutputPaths, ProjectContext context, string outputPath, string configuration)
|
/// <summary>
|
||||||
|
/// Filters which export's RuntimeAssets should get copied to the output path.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// True if the asset should be copied to the output path; otherwise, false.
|
||||||
|
/// </returns>
|
||||||
|
private static bool ShouldCopyExportRuntimeAsset(ProjectContext context, OutputPaths buildOutputPaths, LibraryExport export, LibraryAsset asset)
|
||||||
{
|
{
|
||||||
List<string> filesToPublish = new List<string>();
|
// The current project has the host .exe in its runtime assets, but it shouldn't be copied
|
||||||
|
// to the output path during publish. The host will come from the export that has the real host in it.
|
||||||
|
|
||||||
string[] buildOutputFiles = null;
|
if (context.RootProject.Identity == export.Library.Identity)
|
||||||
|
|
||||||
if (context.ProjectFile.HasRuntimeOutput(configuration))
|
|
||||||
{
|
{
|
||||||
Reporter.Verbose.WriteLine($"publish: using runtime build output files");
|
if (asset.ResolvedPath == buildOutputPaths.RuntimeFiles.Executable)
|
||||||
|
|
||||||
buildOutputFiles = new string[]
|
|
||||||
{
|
{
|
||||||
buildOutputPaths.RuntimeFiles.DepsJson,
|
return false;
|
||||||
buildOutputPaths.RuntimeFiles.RuntimeConfigJson,
|
|
||||||
buildOutputPaths.RuntimeFiles.Config,
|
|
||||||
buildOutputPaths.RuntimeFiles.Assembly,
|
|
||||||
buildOutputPaths.RuntimeFiles.PdbPath,
|
|
||||||
Path.ChangeExtension(buildOutputPaths.RuntimeFiles.Assembly, "xml")
|
|
||||||
};
|
|
||||||
|
|
||||||
filesToPublish.AddRange(buildOutputPaths.RuntimeFiles.Resources());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Reporter.Verbose.WriteLine($"publish: using compilation build output files");
|
|
||||||
|
|
||||||
buildOutputFiles = new string[]
|
|
||||||
{
|
|
||||||
buildOutputPaths.CompilationFiles.Assembly,
|
|
||||||
buildOutputPaths.CompilationFiles.PdbPath,
|
|
||||||
Path.ChangeExtension(buildOutputPaths.CompilationFiles.Assembly, "xml")
|
|
||||||
};
|
|
||||||
|
|
||||||
filesToPublish.AddRange(buildOutputPaths.CompilationFiles.Resources());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var buildOutputFile in buildOutputFiles)
|
|
||||||
{
|
|
||||||
if (File.Exists(buildOutputFile))
|
|
||||||
{
|
|
||||||
filesToPublish.Add(buildOutputFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Reporter.Verbose.WriteLine($"publish: build output file not found {buildOutputFile} ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reporter.Verbose.WriteLine($"publish: Copying build output files:\n {string.Join("\n", filesToPublish)}");
|
return true;
|
||||||
|
|
||||||
PublishFiles(
|
|
||||||
filesToPublish,
|
|
||||||
outputPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool InvokeBuildOnProject(ProjectContext context, string buildBasePath, string configuration)
|
private bool InvokeBuildOnProject(ProjectContext context, string buildBasePath, string configuration)
|
||||||
|
|
Loading…
Reference in a new issue