Skip to content
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: 12 additions & 4 deletions src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using Microsoft.Build.Framework;
using Microsoft.Extensions.DependencyModel;
using NuGet.Packaging;
Expand Down Expand Up @@ -253,7 +254,7 @@ public DependencyContextBuilder WithPackagesThatWereFiltered(Dictionary<PackageI
return this;
}

public DependencyContext Build()
public DependencyContext Build(string[] userRuntimeAssemblies = null)
{
CalculateExcludedLibraries();

Expand All @@ -269,7 +270,7 @@ public DependencyContext Build()
foreach (var library in _dependencyLibraries.Values
.Where(l => !l.ExcludeFromRuntime && l.Type != "runtimepack"))
{
var runtimeLibrary = GetRuntimeLibrary(library);
var runtimeLibrary = GetRuntimeLibrary(library, userRuntimeAssemblies);
if (runtimeLibrary != null)
{
runtimeLibraries.Add(runtimeLibrary);
Expand Down Expand Up @@ -505,7 +506,7 @@ private IEnumerable<RuntimeLibrary> GetRuntimePackLibraries()
});
}

private RuntimeLibrary GetRuntimeLibrary(DependencyLibrary library)
private RuntimeLibrary GetRuntimeLibrary(DependencyLibrary library, string[] userRuntimeAssemblies)
{
GetCommonLibraryProperties(library,
out string hash,
Expand All @@ -527,7 +528,14 @@ private RuntimeLibrary GetRuntimeLibrary(DependencyLibrary library)

if (library.Type == "project" && !(referenceProjectInfo is UnreferencedProjectInfo))
{
runtimeAssemblyGroups.Add(new RuntimeAssetGroup(string.Empty, referenceProjectInfo.OutputName));
var fileName = Path.GetFileNameWithoutExtension(library.Path);
var assemblyPath = userRuntimeAssemblies?.FirstOrDefault(p => Path.GetFileNameWithoutExtension(p).Equals(fileName));
runtimeAssemblyGroups.Add(new RuntimeAssetGroup(string.Empty,
[ new RuntimeFile(
referenceProjectInfo.OutputName,
library.Version.ToString(),
assemblyPath is null || !File.Exists(assemblyPath) ? string.Empty : FileVersionInfo.GetVersionInfo(assemblyPath).FileVersion)
]));

resourceAssemblies.AddRange(referenceProjectInfo.ResourceAssemblies
.Select(r => new ResourceAssembly(r.RelativePath, r.Culture)));
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
.Concat(ResolvedRuntimeTargetsFiles.Select(f => new ResolvedFile(f, true)));
builder = builder.WithResolvedNuGetFiles(resolvedNuGetFiles);

DependencyContext dependencyContext = builder.Build();
DependencyContext dependencyContext = builder.Build(UserRuntimeAssemblies);

var writer = new DependencyContextWriter();
using (var fileStream = File.Create(depsFilePath))
Expand Down