-
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
Generate error message for duplicate items #624
Changes from 3 commits
495afdc
08f2893
cccf1fe
2085098
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.Build.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Microsoft.NET.Build.Tasks | ||
{ | ||
public class CheckForDuplicateItems : TaskBase | ||
{ | ||
[Required] | ||
public ITaskItem [] Items { get; set; } | ||
|
||
[Required] | ||
public string ItemName { get; set; } | ||
|
||
public bool DefaultItemsEnabled { get; set; } | ||
|
||
public bool DefaultItemsOfThisTypeEnabled { get; set; } | ||
|
||
[Required] | ||
public string PropertyNameToDisableDefaultItems { get; set; } | ||
|
||
public string PropertyValueToDisableDefaultItems { get; set; } = "false"; | ||
|
||
[Required] | ||
public string MoreInformationLink { get; set; } | ||
|
||
protected override void ExecuteCore() | ||
{ | ||
if (DefaultItemsEnabled && DefaultItemsOfThisTypeEnabled) | ||
{ | ||
var duplicateItems = Items.GroupBy(i => i.ItemSpec).Where(g => g.Count() > 1).ToList(); | ||
if (duplicateItems.Any()) | ||
{ | ||
string duplicateItemsFormatted = string.Join("; ", duplicateItems.Select(d => $"'{d.Key}'")); | ||
|
||
string message = string.Format(CultureInfo.CurrentCulture, Strings.DuplicateItemsError, | ||
ItemName, | ||
PropertyNameToDisableDefaultItems, | ||
PropertyValueToDisableDefaultItems, | ||
duplicateItemsFormatted); | ||
|
||
Log.LogError(message); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,4 +52,45 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<Content Remove="$(DefaultRemoves)" /> | ||
</ItemGroup> | ||
|
||
<UsingTask TaskName="CheckForDuplicateItems" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" /> | ||
|
||
<Target Name="CheckForDuplicateItems" BeforeTargets="_CheckForInvalidConfigurationAndPlatform"> | ||
|
||
<PropertyGroup> | ||
<!-- TODO: Create a fwlink for this --> | ||
<DefaultItemsMoreInformationLink>https://github.com/dotnet/sdk</DefaultItemsMoreInformationLink> | ||
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. We need to have an acceptable link before we merge. |
||
|
||
<DefaultPackageReferencesEnabled Condition="'$(DisableImplicitFrameworkReferences)' != 'true'">true</DefaultPackageReferencesEnabled> | ||
</PropertyGroup> | ||
|
||
<CheckForDuplicateItems | ||
Items="@(Compile)" | ||
ItemName="Compile" | ||
DefaultItemsEnabled="$(EnableDefaultItems)" | ||
DefaultItemsOfThisTypeEnabled="$(EnableDefaultCompileItems)" | ||
PropertyNameToDisableDefaultItems="EnableDefaultCompileItems" | ||
MoreInformationLink="$(DefaultItemsMoreInformationLink)" | ||
/> | ||
|
||
<CheckForDuplicateItems | ||
Items="@(EmbeddedResource)" | ||
ItemName="EmbeddedResource" | ||
DefaultItemsEnabled="$(EnableDefaultItems)" | ||
DefaultItemsOfThisTypeEnabled="$(EnableDefaultEmbeddedResourceItems)" | ||
PropertyNameToDisableDefaultItems="EnableDefaultEmbeddedResourceItems" | ||
MoreInformationLink="$(DefaultItemsMoreInformationLink)" | ||
/> | ||
|
||
<!-- TODO: Do we check for duplicate content items here, or in the Web SDK? EnableDefaultContentItems isn't defined or used at all by the .NET SDK --> | ||
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 say to do it here because |
||
<CheckForDuplicateItems | ||
Items="@(Content)" | ||
ItemName="Content" | ||
DefaultItemsEnabled="$(EnableDefaultItems)" | ||
DefaultItemsOfThisTypeEnabled="$(EnableDefaultContentItems)" | ||
PropertyNameToDisableDefaultItems="EnableDefaultContentItems" | ||
MoreInformationLink="$(DefaultItemsMoreInformationLink)" | ||
/> | ||
|
||
</Target> | ||
|
||
</Project> |
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.
Can required inputs be null? Change to