Skip to content

Commit 662d157

Browse files
committed
Properly handle main project references
1 parent 5fba7d6 commit 662d157

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,36 @@ public DependencyContext Build(string[] userRuntimeAssemblies = null)
324324
}
325325
}
326326

327+
// Rather than adding the main project's dependencies, we added references to them, i.e., Foo.Reference.dll
328+
// instead of Foo.dll. This adds Foo.dll as a reference directly so another reference can be removed if it
329+
// isn't necessary because of a direct reference from the main project.
330+
if (_includeMainProjectInDepsFile)
331+
{
332+
var mainProjectReferences = _directReferences;
333+
if (IncludeCompilationLibraries && _referenceAssemblies != null)
334+
{
335+
if (mainProjectReferences == null)
336+
{
337+
mainProjectReferences = _referenceAssemblies;
338+
}
339+
else
340+
{
341+
mainProjectReferences = mainProjectReferences.Concat(_referenceAssemblies);
342+
}
343+
}
344+
345+
if (mainProjectReferences != null)
346+
{
347+
foreach (var directReference in mainProjectReferences)
348+
{
349+
if (libraries.TryGetValue(directReference.Name, out var dep))
350+
{
351+
dep.Dependents.Add(_mainProjectInfo.Name);
352+
}
353+
}
354+
}
355+
}
356+
327357
var unprocessedLibraries = runtimeLibraries.ToHashSet();
328358
while (unprocessedLibraries.Any())
329359
{

0 commit comments

Comments
 (0)