-
Notifications
You must be signed in to change notification settings - Fork 41
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
Detect package references containing dll's that were not used during compilation #234
Conversation
@pakrym, |
/cc @Eilon |
Sample output:
|
<Sdk_FindUnusedReferences Assembly="@(IntermediateAssembly)" References="@(ReferencePath)" Packages="@(PackageDependencies)" Files="@(FileDefinitions)" > | ||
<Output TaskParameter="UnusedReferences" ItemName="UnusedReferences" /> | ||
</Sdk_FindUnusedReferences> | ||
<Warning Condition="'@(UnusedReferences)' != ''" Text="Unused reference in $(MSBuildProjectFile)/$(TargetFramework) %(UnusedReferences.Identity) from package %(UnusedReferences.PackageName)" /> |
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.
Would it be possible to make this a verifier rule? We really don't have a good way to suppress individual warnings here and I rather not spend time every compilation doing extra work.
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.
Not really, I need list of things that got passed to compiler and it's not easy to infer from assets.json anymore :(.
How many warnings do you get when building Universe with this change? I'm concerned this will further clutter our build output with warnings that are not actionable. I think with a few extra checks, this target could make strong recommendations about whether a package is safe to remove. Those additional checks might include:
|
@natemcmaster tons of warnings right now, this definitely needs to be disabled for tests and samples. Maybe this should be run only occasionally to cleanup libraries and not on every run, or it needs a way to specify exclusions.
|
+1 reduce noise.
|
+1 Does this give warning in the scenario where I have a direct package reference but is not really required to be specified as its going to be brought transitively by another direct package reference that I have? (I feel VS should have built-in support for this) |
@kichalla no. It gives a warning when you reference a package but don't use it's dll, sometimes it happens that you at the same time use dll of transitive dependency in brings, so you can replace package reference with it's transitive dependency. |
This is disabled by default. |
Is there a lot of utility in this if it's disabled by default? |
I will do aspnet/Coherence#175 by enabling it per repo maybe fix more bugs and if we feel it gives useful results I'm going to enable it by default. |
StringComparer.OrdinalIgnoreCase); | ||
|
||
using (var fileStream = File.OpenRead(Assembly)) | ||
using (PEReader reader = new PEReader(fileStream)) |
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.
var
all day everyday.
Note: it does not tell you that you can safely remove package reference it just points out which dll's were not used during compilation. Package that has unused dll could have brought transitive reference that is used, content files, etc.
Sometimes package references are unused only for one of the targets so users need to pay attention to which target produced the warning.