diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs b/src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs index 1adef018d052..3a6579001523 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs @@ -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; @@ -253,7 +254,7 @@ public DependencyContextBuilder WithPackagesThatWereFiltered(Dictionary !l.ExcludeFromRuntime && l.Type != "runtimepack")) { - var runtimeLibrary = GetRuntimeLibrary(library); + var runtimeLibrary = GetRuntimeLibrary(library, userRuntimeAssemblies); if (runtimeLibrary != null) { runtimeLibraries.Add(runtimeLibrary); @@ -505,7 +506,7 @@ private IEnumerable GetRuntimePackLibraries() }); } - private RuntimeLibrary GetRuntimeLibrary(DependencyLibrary library) + private RuntimeLibrary GetRuntimeLibrary(DependencyLibrary library, string[] userRuntimeAssemblies) { GetCommonLibraryProperties(library, out string hash, @@ -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))); diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs index 090e7d4514cb..0ca1f6f2c200 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs @@ -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))