-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for transitive framework references #3221
Changes from all commits
853ea6f
b4bd8b1
fb990e9
1e55736
4687065
d66e656
4d31c70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,11 @@ public sealed class ResolvePackageAssets : TaskBase | |
/// </summary> | ||
public bool DisableTransitiveProjectReferences { get; set; } | ||
|
||
/// <summary> | ||
/// Disables FrameworkReferences from referenced projects or packages | ||
/// </summary> | ||
public bool DisableTransitiveFrameworkReferences { get; set; } | ||
|
||
/// <summary> | ||
/// Do not add references to framework assemblies as specified by packages. | ||
/// </summary> | ||
|
@@ -167,6 +172,9 @@ public sealed class ResolvePackageAssets : TaskBase | |
[Output] | ||
public ITaskItem[] FrameworkAssemblies { get; private set; } | ||
|
||
[Output] | ||
public ITaskItem[] FrameworkReferences { get; private set; } | ||
|
||
/// <summary> | ||
/// Full paths to native libraries from packages to run against. | ||
/// </summary> | ||
|
@@ -262,7 +270,7 @@ public sealed class ResolvePackageAssets : TaskBase | |
//////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
private const int CacheFormatSignature = ('P' << 0) | ('K' << 8) | ('G' << 16) | ('A' << 24); | ||
private const int CacheFormatVersion = 7; | ||
private const int CacheFormatVersion = 8; | ||
private static readonly Encoding TextEncoding = Encoding.UTF8; | ||
private const int SettingsHashLength = 256 / 8; | ||
private HashAlgorithm CreateSettingsHash() => SHA256.Create(); | ||
|
@@ -290,6 +298,7 @@ private void ReadItemGroups() | |
CompileTimeAssemblies = reader.ReadItemGroup(); | ||
ContentFilesToPreprocess = reader.ReadItemGroup(); | ||
FrameworkAssemblies = reader.ReadItemGroup(); | ||
FrameworkReferences = reader.ReadItemGroup(); | ||
NativeLibraries = reader.ReadItemGroup(); | ||
PackageFolders = reader.ReadItemGroup(); | ||
ResourceAssemblies = reader.ReadItemGroup(); | ||
|
@@ -366,6 +375,7 @@ internal byte[] HashSettings() | |
writer.Write(DisableFrameworkAssemblies); | ||
writer.Write(DisableRuntimeTargets); | ||
writer.Write(DisableTransitiveProjectReferences); | ||
writer.Write(DisableTransitiveFrameworkReferences); | ||
writer.Write(DotNetAppHostExecutableNameWithoutExtension); | ||
writer.Write(EmitAssetsLogMessages); | ||
writer.Write(EnsureRuntimePackageDependencies); | ||
|
@@ -685,6 +695,7 @@ private void WriteItemGroups() | |
WriteItemGroup(WriteCompileTimeAssemblies); | ||
WriteItemGroup(WriteContentFilesToPreprocess); | ||
WriteItemGroup(WriteFrameworkAssemblies); | ||
WriteItemGroup(WriteFrameworkReferences); | ||
WriteItemGroup(WriteNativeLibraries); | ||
WriteItemGroup(WritePackageFolders); | ||
WriteItemGroup(WriteResourceAssemblies); | ||
|
@@ -1103,6 +1114,31 @@ private void WriteTransitiveProjectReferences() | |
} | ||
} | ||
|
||
private void WriteFrameworkReferences() | ||
{ | ||
if (_task.DisableTransitiveFrameworkReferences) | ||
{ | ||
return; | ||
} | ||
|
||
HashSet<string> writtenFrameworkReferences = null; | ||
|
||
foreach (var library in _runtimeTarget.Libraries) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a DisableTransitiveFrameworkReferences here to match the DisableTransitiveProjectReferences. Also, I think we should dedupe here like we do for framework assemblies. Better to keep the cache small than to dedupe in targets afterwards. Finally, if transitive framework references are disabled, we should change resolve framework references to not download all packs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nguerrera I'm not sure there's value in opting out of transitive FrameworkReferences. There's no split between compile and runtime assets for framework references, so disabling transitive framework references would either have no effect (since you already have the same direct references), or would break your app at runtime (since the framework your dependency needs isn't written to the runtimeconfig). What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still like there to be an escape hatch. |
||
{ | ||
foreach (var frameworkReference in library.FrameworkReferences) | ||
{ | ||
if (writtenFrameworkReferences == null) | ||
{ | ||
writtenFrameworkReferences = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
} | ||
if (writtenFrameworkReferences.Add(frameworkReference)) | ||
{ | ||
WriteItem(frameworkReference); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void WriteItems<T>( | ||
LockFileTarget target, | ||
Func<LockFileTargetLibrary, IEnumerable<T>> getAssets, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed. It is done by arcade. Any reason why you are adding it back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arcade doesn't give you meaningful names for the test results or the zip files. See here for example:
There's discussion of this on this arcade PR: dotnet/arcade#2525. I made a similar change to core-sdk here: dotnet/installer#1609