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

Show duplicate item errors due to implicit items in design-time builds #675

Merged

Conversation

dsplaisted
Copy link
Member

In design-time builds, remove duplicate items so that we can get a valid compilation and don't get a flood of errors due to having no references

Fixes #664

In design-time builds, remove duplicate items so that we can get a valid compilation and don't get a flood of errors due to having no references

Fixes dotnet#664
@dsplaisted
Copy link
Member Author

@srivatsn @nguerrera @natidea @davkean for review

Escrow template:

Scenario

In #624, we added a better error message for the below scenario. However, the better error message was not generated in design-time builds, so when a project is opened the error list will show the less specific error message from the compiler, as well as many other errors that types can't be resolved, etc., because the design-time build failed and so the design-time compilation doesn't have any references. This change adds the more helpful error to the design-time build and prevents the other errors from showing up in the design-time build by de-duplicating the items (only in the design-time build).

Scenario for error message in general:

A user upgrades from RC2 to RC3. The projects they created with RC2 will generate compile errors saying that the source files were specified multiple times. This is because we now include the source files implicitly. This change will generate an error message that explains how to fix the issue:

error : Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. The duplicate items were: 'Class1.cs'; 'DuplicateCompileItems.cs'

Bug

#664

Workarounds

Perform a build in VS, or on the command line

Risk

Low to medium - Tests should cover any impacted scenarios for the command line. VS design time experience was manually validated.

Performance Impact

Low - Runs an additional target during design-time build to check for duplicates items.

Regression Analysis

n/a

@srivatsn
Copy link
Contributor

Tagging @MattGertz for RC3.

@MattGertz
Copy link

@srivatsn Can you get this on the RC3 mail thread I started this morning so we can get it in front of JoC?

if (DefaultItemsEnabled && DefaultItemsOfThisTypeEnabled)
{
var duplicateItems = Items.GroupBy(i => i.ItemSpec).Where(g => g.Count() > 1).ToList();
var itemGroups = Items.GroupBy(i => i.ItemSpec);
Copy link
Contributor

Choose a reason for hiding this comment

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

i => i.ItemSpec [](start = 47, length = 15)

For non-windows platforms, I think we need to handle "duplicate" items with different casing (e.g. Class1.cs and class1.cs) by making this Items.GroupBy(i => i.ItemSpec, StringComparer.OrdinalIgnoreCase)

Copy link
Contributor

@nguerrera nguerrera Jan 18, 2017

Choose a reason for hiding this comment

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

I would think it would be the opposite: e.g. case-insensitive better for Windows, case-sensitive better for Linux. It would be valid (though asking for serious trouble) on some file systems to have two different files differing only by case and we`d insert an error where compilation would have succeeded. I am not sure what the best answer is here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I changed my mind. If we try to make this case insensitive, then even the implicit glob **/*.cs would fail if a user had both Class1.cs and class1.cs on Linux.

I think the implication of leaving it case sensitive is that on Windows, a user could still get a duplicate sources error from compiler even with this fix. (E.g. if they have implicit **/*.cs, <Compile Include="Class1.cs" /> and the file is actually named class1.cs)

Copy link
Contributor

Choose a reason for hiding this comment

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

A customer ran into a similar issue - #679. Basically they had different casing for NetStandard.Library and we weren't deduping.

Copy link
Contributor

@natidea natidea left a comment

Choose a reason for hiding this comment

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

Holding for thoughts on handling "duplicate" items with different casing. Otherwise LGTM

@srivatsn
Copy link
Contributor

Proactively merging to get a build out for shiproom.

@srivatsn srivatsn merged commit b616fc4 into dotnet:dev15-rc3 Jan 18, 2017
@dsplaisted dsplaisted deleted the design-time-duplicate-item-error-664 branch January 31, 2017 14:41
mmitche pushed a commit to mmitche/sdk that referenced this pull request Jun 5, 2020
…0190601.4 (dotnet#675)

- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-preview6.19301.4
- Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-preview6.19301.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants