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

Optionally output unresolved assembly conflicts #5990

Merged
merged 6 commits into from
Jan 8, 2021

Conversation

Forgind
Copy link
Member

@Forgind Forgind commented Dec 29, 2020

Fixes #5934.

@dsplaisted, does this look how you expected?

@dsplaisted
Copy link
Member

dsplaisted commented Dec 29, 2020

The additional parameter / output to the task look like what we need. The common targets would also need to be updated to use those when calling the ResolveAssemblyReference task.

For the implementation, it should do the following. I wasn't sure but it looked like it wasn't:

  • Warnings should still be generated even if OutputUnresolvedAssemblyConflicts is true
  • The output items should use the assembly name (possibly with .dll on the end, possibly not) as the ItemSpec, not the full log message. That will allow code to check whether (for example) there is a conflict for the Microsoft.Windows.SDK.NET.dll assembly. Additional information can be included in the item metadata.

Thanks!

@Forgind
Copy link
Member Author

Forgind commented Dec 29, 2020

Does that look better? The extra information you'd want in metadata is the conflicting versions and how each was (directly or indirectly) referenced? (I wasn't sure, so I haven't added that yet.)

Copy link
Member

@dsplaisted dsplaisted left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like what we wanted, as far as I can tell.


if (OutputUnresolvedAssemblyConflicts)
{
_unresolvedConflicts.Add(new TaskItem(assemblyName.Name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would include the log message with the human-readable details in the metadata for this item.

We don't currently have a use case for programmatically processing data such as conflicting version numbers, how the assembly was referenced, etc. I would say if it's straightforward to include, then go ahead and do so. But if not, then skip it for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicting version numbers is easy, so I included that. How it's referenced is doable, but it's a little verbose, since there could be multiple levels of dependencies (A depends on B depends on C depends on D depends on the conflicting dll). I can add it later if we decide we need it, though.

@@ -2233,6 +2235,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Output TaskParameter="FilesWritten" ItemName="FileWrites"/>
<Output TaskParameter="DependsOnSystemRuntime" PropertyName="DependsOnSystemRuntime"/>
<Output TaskParameter="DependsOnNETStandard" PropertyName="_DependsOnNETStandard"/>
<Output TaskParameter="UnresolvedAssemblyConflicts" ItemName="UnresolvedAssemblyConflicts"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to use a name that's more likely to be unique. Similar to the pattern for the input property, that could be ResolveAssemblyReferenceUnresolvedAssemblyConflicts.

@Forgind Forgind marked this pull request as ready for review December 29, 2020 18:28
@@ -990,16 +1009,36 @@ List<Exception> generalResolutionExceptions
// Log the reference which lost the conflict and the dependencies and source items which caused it.
LogReferenceDependenciesAndSourceItemsToStringBuilder(fusionName, conflictCandidate, logDependencies.AppendLine());

string toOutput;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
string toOutput;
string toOutput = StringBuilderCache.GetStringAndRelease(logConflict);

Both if and else do this as their first statement.

Comment on lines 930 to 935
public ITaskItem[] UnresolvedAssemblyConflicts {
get
{
return _unresolvedConflicts.ToArray();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
public ITaskItem[] UnresolvedAssemblyConflicts {
get
{
return _unresolvedConflicts.ToArray();
}
}
public ITaskItem[] UnresolvedAssemblyConflicts => _unresolvedConflicts.ToArray();

Comment on lines 1039 to 1040
{"victorVersionNumber", victor.ReferenceVersion.ToString() },
{"victimVersionNumber", conflictCandidate.ReferenceVersion.ToString() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit: Missing space after {.

// This does an extra allocation, so only do it when necessary.
if (OutputUnresolvedAssemblyConflicts)
{
toOutput += '\n' + extra;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not be more structured add extra in its own metadatum? Something like:

{ "logMessage", toOutput },
{ "logMessageDetails", extra }

Copy link
Member

@benvillalobos benvillalobos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the PR

If a user sets ResolveAssemblyReferenceOutputUnresolvedAssemblyConflicts to true, RAR will populate the output item ResolveAssemblyReferenceUnresolvedAssemblyConflicts, which the SDK will pick up and throw the appropriate error on.

LGTM, pending 2 comments.

@@ -214,6 +215,12 @@ public bool IgnoreTargetFrameworkAttributeVersionMismatch
/// </remarks>
public bool FindDependenciesOfExternallyResolvedReferences { get; set; }

/// <summary>
/// If true, outputs any unresolved assembly conflicts (MSB3277) in UnresolvedAssemblyConflicts
/// instead of logging them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of logging them.

doesn't it do both?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Fixed. That was a holdover from how I'd originally designed it.

@@ -3686,6 +3686,37 @@ public void ConflictGeneratesMessageReferencingAssemblyName()
warningMessage.ShouldContain(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ResolveAssemblyReference.FourSpaceIndent", ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ResolveAssemblyReference.ReferenceDependsOn", "D, Version=1.0.0.0, CulTUre=neutral, PublicKeyToken=aaaaaaaaaaaaaaaa", Path.Combine(s_myLibraries_V1Path, "D.dll"))));
}

[Fact]
public void ConflictOutputsExtraInformationOnDemand()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make this a theory and test what happens when the item has the .dll extension? @dsplaisted is there a concrete answer for including .dll in the assembly name? Or did your comment, "possibly with .dll possibly not," refer to the fact that assemblyName.Name may not have the extension along with it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood him to mean that the SDK can handle the output having the .dll extension or not having it—it's the same information, just presented slightly differently. Since I'm creating the item, and I went with no .dll extension, that shouldn't be an issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure whether the assembly name processed by ResolveAssemblyReference would have the .dll extension on it. If it consistently does not have the extension, then I would leave it out. It's also theoretically possible to reference an .exe, I believe.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The summary behind assemblyName.Name:

Gets or sets the simple name of the assembly. This is usually, but not necessarily,
the file name of the manifest file of the assembly, minus its extension.

Looks like the SDK will have to account for both scenarios, unless there's a preference on how we handle it here. I'm okay with either scenario.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like MSBuild shouldn't do anything special here then (ie don't add the .dll extension).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support generating errors for unresolved assembly conflicts from ResolveAssemblyReference
5 participants