Skip to content

Commit c352fb2

Browse files
author
Jason Zhai
committed
Merge branch 'release/6.0.4xx' into release/7.0.1xx
2 parents 93aa9f1 + fc8b78c commit c352fb2

File tree

16 files changed

+351
-95
lines changed

16 files changed

+351
-95
lines changed

src/Assets/DesktopTestProjects/MultiTFMXunitProject/XUnitProject/XUnitProject.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>net462;netcoreapp3.1</TargetFrameworks>
5+
<TargetFrameworks>net462;$(CurrentTargetFramework)</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>

src/Assets/DesktopTestProjects/NETFrameworkReferenceNETStandard20/MultiTFMTestApp/MultiTFMTestApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
5+
<TargetFrameworks>$(CurrentTargetFramework);net462</TargetFrameworks>
66
</PropertyGroup>
77

88
<ItemGroup>

src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenADependencyContextBuilder.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void ItBuildsDependencyContextsFromProjectLockFiles(
4040
object[] resolvedNuGetFiles)
4141
{
4242
LockFile lockFile = TestLockFiles.GetLockFile(mainProjectName);
43+
LockFileLookup lockFileLookup = new LockFileLookup(lockFile);
4344

4445
SingleProjectInfo mainProject = SingleProjectInfo.Create(
4546
"/usr/Path",
@@ -52,8 +53,9 @@ public void ItBuildsDependencyContextsFromProjectLockFiles(
5253
ReferenceInfo.CreateDirectReferenceInfos(
5354
referencePaths ?? new ITaskItem[] { },
5455
referenceSatellitePaths ?? new ITaskItem[] { },
55-
projectContextHasProjectReferences: false,
56-
i => true);
56+
lockFileLookup: lockFileLookup,
57+
i => true,
58+
true);
5759

5860
ProjectContext projectContext = lockFile.CreateProjectContext(
5961
FrameworkConstants.CommonFrameworks.NetCoreApp10.GetShortFolderName(),
@@ -67,7 +69,7 @@ public void ItBuildsDependencyContextsFromProjectLockFiles(
6769
resolvedNuGetFiles = Array.Empty<ResolvedFile>();
6870
}
6971

70-
DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph: null, projectContext: projectContext)
72+
DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph: null, projectContext: projectContext, libraryLookup: lockFileLookup)
7173
.WithDirectReferences(directReferences)
7274
.WithCompilationOptions(compilationOptions)
7375
.WithResolvedNuGetFiles((ResolvedFile[]) resolvedNuGetFiles)
@@ -264,7 +266,7 @@ private DependencyContext BuildDependencyContextWithReferenceAssemblies(bool use
264266
useCompilationOptions ? CreateCompilationOptions() :
265267
null;
266268

267-
DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph: null, projectContext: projectContext)
269+
DependencyContext dependencyContext = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph: null, projectContext: projectContext, libraryLookup: new LockFileLookup(lockFile))
268270
.WithReferenceAssemblies(ReferenceInfo.CreateReferenceInfos(referencePaths))
269271
.WithCompilationOptions(compilationOptions)
270272
.Build();
@@ -325,7 +327,7 @@ public void ItCanGenerateTheRuntimeFallbackGraph()
325327
void CheckRuntimeFallbacks(string runtimeIdentifier, int fallbackCount)
326328
{
327329
projectContext.LockFileTarget.RuntimeIdentifier = runtimeIdentifier;
328-
var dependencyContextBuilder = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph, projectContext);
330+
var dependencyContextBuilder = new DependencyContextBuilder(mainProject, includeRuntimeFileVersions: false, runtimeGraph, projectContext, libraryLookup: new LockFileLookup(lockFile));
329331
var runtimeFallbacks = dependencyContextBuilder.Build().RuntimeGraph;
330332

331333
runtimeFallbacks

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ internal class DependencyContextBuilder
4747

4848
private const string NetCorePlatformLibrary = "Microsoft.NETCore.App";
4949

50-
public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, RuntimeGraph runtimeGraph, ProjectContext projectContext)
50+
public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, RuntimeGraph runtimeGraph, ProjectContext projectContext, LockFileLookup libraryLookup)
5151
{
5252
_mainProjectInfo = mainProjectInfo;
5353
_includeRuntimeFileVersions = includeRuntimeFileVersions;
5454
_runtimeGraph = runtimeGraph;
5555

56-
var libraryLookup = new LockFileLookup(projectContext.LockFile);
57-
5856
_dependencyLibraries = projectContext.LockFileTarget.Libraries
5957
.Select(lockFileTargetLibrary =>
6058
{

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public class GenerateDepsFile : TaskWithAssemblyResolveHooks
9494

9595
public bool IncludeRuntimeFileVersions { get; set; }
9696

97+
public bool IncludeProjectsNotInAssetsFile { get; set; }
98+
9799
[Required]
98100
public string RuntimeGraphPath { get; set; }
99101

@@ -125,20 +127,19 @@ private Dictionary<PackageIdentity, string> GetFilteredPackages()
125127

126128
private void WriteDepsFile(string depsFilePath)
127129
{
128-
ProjectContext projectContext;
129-
if (AssetsFilePath == null)
130-
{
131-
projectContext = null;
132-
}
133-
else
130+
ProjectContext projectContext = null;
131+
LockFileLookup lockFileLookup = null;
132+
if (AssetsFilePath != null)
134133
{
135134
LockFile lockFile = new LockFileCache(this).GetLockFile(AssetsFilePath);
136135
projectContext = lockFile.CreateProjectContext(
137-
TargetFramework,
138-
RuntimeIdentifier,
139-
PlatformLibraryName,
140-
RuntimeFrameworks,
141-
IsSelfContained);
136+
TargetFramework,
137+
RuntimeIdentifier,
138+
PlatformLibraryName,
139+
RuntimeFrameworks,
140+
IsSelfContained);
141+
142+
lockFileLookup = new LockFileLookup(lockFile);
142143
}
143144

144145
CompilationOptions compilationOptions = CompilationOptionsConverter.ConvertFrom(CompilerOptions);
@@ -156,13 +157,15 @@ private void WriteDepsFile(string depsFilePath)
156157
IEnumerable<ReferenceInfo> referenceAssemblyInfos =
157158
ReferenceInfo.CreateReferenceInfos(ReferenceAssemblies);
158159

159-
// If there is a generated asset file. The projectContext will have project reference.
160-
// So remove it from directReferences to avoid duplication
161-
var projectContextHasProjectReferences = projectContext != null;
160+
// If there is a generated asset file, the projectContext will contain most of the project references.
161+
// So remove any project reference contained within projectContext from directReferences to avoid duplication
162162
IEnumerable<ReferenceInfo> directReferences =
163-
ReferenceInfo.CreateDirectReferenceInfos(ReferencePaths,
163+
ReferenceInfo.CreateDirectReferenceInfos(
164+
ReferencePaths,
164165
ReferenceSatellitePaths,
165-
projectContextHasProjectReferences, isUserRuntimeAssembly);
166+
lockFileLookup,
167+
isUserRuntimeAssembly,
168+
IncludeProjectsNotInAssetsFile);
166169

167170
IEnumerable<ReferenceInfo> dependencyReferences =
168171
ReferenceInfo.CreateDependencyReferenceInfos(ReferenceDependencyPaths, ReferenceSatellitePaths, isUserRuntimeAssembly);
@@ -210,7 +213,7 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
210213
RuntimeGraph runtimeGraph =
211214
IsSelfContained ? new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath) : null;
212215

213-
builder = new DependencyContextBuilder(mainProject, IncludeRuntimeFileVersions, runtimeGraph, projectContext);
216+
builder = new DependencyContextBuilder(mainProject, IncludeRuntimeFileVersions, runtimeGraph, projectContext, lockFileLookup);
214217
}
215218
else
216219
{

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,49 @@ public static IEnumerable<ReferenceInfo> CreateReferenceInfos(IEnumerable<ITaskI
5454
public static IEnumerable<ReferenceInfo> CreateDirectReferenceInfos(
5555
IEnumerable<ITaskItem> referencePaths,
5656
IEnumerable<ITaskItem> referenceSatellitePaths,
57-
bool projectContextHasProjectReferences,
58-
Func<ITaskItem, bool> isRuntimeAssembly)
57+
LockFileLookup lockFileLookup,
58+
Func<ITaskItem, bool> isRuntimeAssembly,
59+
bool includeProjectsNotInAssetsFile)
5960
{
60-
61-
bool filterOutProjectReferenceIfInProjectContextAlready(ITaskItem referencePath)
61+
bool lockFileContainsProject(ITaskItem referencePath)
6262
{
63-
return (projectContextHasProjectReferences ? !IsProjectReference(referencePath) : true);
63+
if (lockFileLookup == null)
64+
{
65+
return false;
66+
}
67+
68+
if (!IsProjectReference(referencePath))
69+
{
70+
return false;
71+
}
72+
73+
if (!includeProjectsNotInAssetsFile)
74+
{
75+
return true;
76+
}
77+
78+
string projectName;
79+
string projectFilePath = referencePath.GetMetadata(MetadataKeys.MSBuildSourceProjectFile);
80+
if (!string.IsNullOrEmpty(projectFilePath))
81+
{
82+
projectName = Path.GetFileNameWithoutExtension(projectFilePath);
83+
}
84+
else
85+
{
86+
// fall back to using the path to the output DLL
87+
projectName = Path.GetFileNameWithoutExtension(referencePath.ItemSpec);
88+
if (string.IsNullOrEmpty(projectName))
89+
{
90+
// unexpected - let's assume this project was already included in the assets file.
91+
return true;
92+
}
93+
}
94+
95+
return lockFileLookup.GetProject(projectName) != null;
6496
}
6597

6698
IEnumerable<ITaskItem> directReferencePaths = referencePaths
67-
.Where(r => filterOutProjectReferenceIfInProjectContextAlready(r) && !IsNuGetReference(r) && isRuntimeAssembly(r));
99+
.Where(r => !lockFileContainsProject(r) && !IsNuGetReference(r) && isRuntimeAssembly(r));
68100

69101
return CreateFilteredReferenceInfos(directReferencePaths, referenceSatellitePaths);
70102
}
@@ -147,7 +179,7 @@ private static string GetVersion(ITaskItem referencePath)
147179
if (!string.IsNullOrEmpty(fusionName))
148180
{
149181
AssemblyName assemblyName = new AssemblyName(fusionName);
150-
version = assemblyName.Version.ToString();
182+
version = assemblyName.Version?.ToString();
151183
}
152184

153185
if (string.IsNullOrEmpty(version))

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.DesignerSupport.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Copyright (c) .NET Foundation. All rights reserved.
6868
ResolvedRuntimeTargetsFiles="@(RuntimeTargetsCopyLocalItems)"
6969
TargetFramework="$(TargetFramework)"
7070
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
71+
IncludeProjectsNotInAssetsFile="$(IncludeProjectsNotInAssetsFileInDepsFile)"
7172
/>
7273

7374
<ItemGroup>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,8 @@ Copyright (c) .NET Foundation. All rights reserved.
986986
IsSelfContained="$(SelfContained)"
987987
IsSingleFile="$(_IsSingleFilePublish)"
988988
IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)"
989-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"/>
989+
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
990+
IncludeProjectsNotInAssetsFile="$(IncludeProjectsNotInAssetsFileInDepsFile)"/>
990991

991992
<ItemGroup>
992993
<ResolvedFileToPublish Include="$(IntermediateDepsFilePath)">

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ Copyright (c) .NET Foundation. All rights reserved.
125125
<MetadataUpdaterSupport Condition="'$(MetadataUpdaterSupport)' == '' and '$(Configuration)' != 'Debug'">false</MetadataUpdaterSupport>
126126
</PropertyGroup>
127127

128+
<PropertyGroup>
129+
<!-- Turn off IncludeProjectsNotInAssetsFileInDepsFile by default. -->
130+
<IncludeProjectsNotInAssetsFileInDepsFile Condition="'$(IncludeProjectsNotInAssetsFileInDepsFile)' == ''">false</IncludeProjectsNotInAssetsFileInDepsFile>
131+
</PropertyGroup>
132+
128133
<PropertyGroup>
129134
<CoreBuildDependsOn>
130135
_CheckForBuildWithNoBuild;
@@ -213,7 +218,8 @@ Copyright (c) .NET Foundation. All rights reserved.
213218
ResolvedRuntimeTargetsFiles="@(RuntimeTargetsCopyLocalItems)"
214219
IsSelfContained="$(SelfContained)"
215220
IncludeRuntimeFileVersions="$(IncludeFileVersionsInDependencyFile)"
216-
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"/>
221+
RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)"
222+
IncludeProjectsNotInAssetsFile="$(IncludeProjectsNotInAssetsFileInDepsFile)"/>
217223

218224
<ItemGroup>
219225
<!-- Do this in an ItemGroup instead of as an output parameter of the GenerateDepsFile task so that it still gets added to the item set

0 commit comments

Comments
 (0)