Skip to content
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

Merged
merged 7 commits into from
May 14, 2019
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
34 changes: 32 additions & 2 deletions eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
parameters:
name: ${{ parameters.agentOs }}
enableMicrobuild: true
enablePublishBuildArtifacts: true
enablePublishBuildAssets: true
enablePublishTestResults: true
enableTelemetry: true
helixRepo: dotnet/sdk
pool: ${{ parameters.pool }}
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
${{ if ne(parameters.strategy, '') }}:
strategy: ${{ parameters.strategy }}
workspace:
clean: all
variables:
- ${{ insert }}: ${{ parameters.variables }}
- _AgentOSName: ${{ parameters.agentOs }}
Expand Down Expand Up @@ -151,3 +151,33 @@ jobs:
BuildConfig: $(_BuildConfig)
BlobFeedUrl: $(PB_PublishBlobFeedUrl)
PublishType: $(_PublishType)

- task: PublishTestResults@1
Copy link
Contributor

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?

Copy link
Member Author

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:

image

There's discussion of this on this arcade PR: dotnet/arcade#2525. I made a similar change to core-sdk here: dotnet/installer#1609

displayName: Publish Test Results
inputs:
testRunner: XUnit
testResultsFiles: 'artifacts/TestResults/$(_BuildConfig)/*.xml'
testRunTitle: '$(_AgentOSName)_$(Agent.JobName)'
platform: '$(BuildPlatform)'
configuration: '$(_BuildConfig)'
condition: not(succeeded())

- task: CopyFiles@2
displayName: Gather Logs
inputs:
SourceFolder: '$(Build.SourcesDirectory)/artifacts'
Contents: |
log/$(_BuildConfig)/**/*
TestResults/$(_BuildConfig)/**/*
TargetFolder: '$(Build.ArtifactStagingDirectory)'
continueOnError: true
condition: not(succeeded())

- task: PublishBuildArtifacts@1
displayName: Publish Logs to VSTS
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: '$(_AgentOSName)_$(Agent.JobName)_$(Build.BuildNumber)'
publishLocation: Container
continueOnError: true
condition: not(succeeded())
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override void ExecuteCore()
NormalizeVersion(kfr.TargetFramework.Version) == normalizedTargetFrameworkVersion)
.ToList();

var frameworkReferenceMap = FrameworkReferences.ToDictionary(fr => fr.ItemSpec);
var frameworkReferenceMap = FrameworkReferences.ToDictionary(fr => fr.ItemSpec, StringComparer.OrdinalIgnoreCase);

List<ITaskItem> packagesToDownload = new List<ITaskItem>();
List<ITaskItem> legacyFrameworkPackages = new List<ITaskItem>();
Expand Down
38 changes: 37 additions & 1 deletion src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -685,6 +695,7 @@ private void WriteItemGroups()
WriteItemGroup(WriteCompileTimeAssemblies);
WriteItemGroup(WriteContentFilesToPreprocess);
WriteItemGroup(WriteFrameworkAssemblies);
WriteItemGroup(WriteFrameworkReferences);
WriteItemGroup(WriteNativeLibraries);
WriteItemGroup(WritePackageFolders);
WriteItemGroup(WriteResourceAssemblies);
Expand Down Expand Up @@ -1103,6 +1114,31 @@ private void WriteTransitiveProjectReferences()
}
}

private void WriteFrameworkReferences()
{
if (_task.DisableTransitiveFrameworkReferences)
{
return;
}

HashSet<string> writtenFrameworkReferences = null;

foreach (var library in _runtimeTarget.Libraries)
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Publish="true" />
</ItemGroup>
<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETStandard' And '$(_TargetFrameworkVersionWithoutV)' >= '2.1'">
<FrameworkReference Include="NETStandard.Library" IsImplicitlyDefined="true" Pack="false"/>
<FrameworkReference Include="NETStandard.Library" IsImplicitlyDefined="true" Pack="false" PrivateAssets="All"/>
</ItemGroup>

<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
Expand All @@ -66,6 +66,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<FrameworkReference Include="Microsoft.NETCore.App" IsImplicitlyDefined="true"
Pack="false"
PrivateAssets="All"
Condition="('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '3.0')"/>

</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ Copyright (c) .NET Foundation. All rights reserved.

</Target>

<Target Name="AddTransitiveFrameworkReferences" AfterTargets="ResolvePackageAssets"
Condition="'@(TransitiveFrameworkReference)' != ''" >

<ItemGroup>
<FrameworkReference Include="@(TransitiveFrameworkReference)" Exclude="@(FrameworkReference)"/>
</ItemGroup>

</Target>

<UsingTask TaskName="GetPackageDirectory" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
<UsingTask TaskName="ResolveTargetingPackAssets" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Copyright (c) .NET Foundation. All rights reserved.
DisableFrameworkAssemblies="$(DisableLockFileFrameworks)"
DisableRuntimeTargets="$(DisableRuntimeTargets)"
DisableTransitiveProjectReferences="$(DisableTransitiveProjectReferences)"
DisableTransitiveFrameworkReferences="$(DisableTransitiveFrameworkReferences)"
DotNetAppHostExecutableNameWithoutExtension="$(_DotNetAppHostExecutableNameWithoutExtension)"
ShimRuntimeIdentifiers="@(_PackAsToolShimRuntimeIdentifiers)"
EnsureRuntimePackageDependencies="$(EnsureRuntimePackageDependencies)"
Expand All @@ -259,6 +260,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Output TaskParameter="ApphostsForShimRuntimeIdentifiers" ItemName="_ApphostsForShimRuntimeIdentifiersResolvePackageAssets" />
<Output TaskParameter="ContentFilesToPreprocess" ItemName="_ContentFilesToPreprocess" />
<Output TaskParameter="FrameworkAssemblies" ItemName="ResolvedFrameworkAssemblies" />
<Output TaskParameter="FrameworkReferences" ItemName="TransitiveFrameworkReference" />
<Output TaskParameter="NativeLibraries" ItemName="NativeCopyLocalItems" />
<Output TaskParameter="ResourceAssemblies" ItemName="ResourceCopyLocalItems" />
<Output TaskParameter="RuntimeAssemblies" ItemName="RuntimeCopyLocalItems" />
Expand Down
Loading