Skip to content

Commit c668502

Browse files
committed
Add warning when Authors == AssemblyName
The SDKs set this default in Microsoft.NET.DefaultAssemblyInfo.targets, but it's not really a very useful default (like the Description one). So we flag this as a warning now. We take over NG0102 since that wasn't active in any way (analyzers never get 4k chars of a property anyway).
1 parent 6e6ff26 commit c668502

File tree

5 files changed

+67
-44
lines changed

5 files changed

+67
-44
lines changed

src/CodeAnalysis/CodeAnalysis.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<IsPackable>false</IsPackable>
77
<PackFolder>analyzers/dotnet</PackFolder>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
9+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
910
</PropertyGroup>
1011

1112
<ItemGroup>
@@ -16,4 +17,8 @@
1617
<PackageReference Include="Devlooped.SponsorLink" Version="0.9.9" />
1718
</ItemGroup>
1819

20+
<ItemGroup>
21+
<None Update="NuGetizer.CodeAnalysis.targets" PackFolder="build" CopyToOutputDirectory="PreserveNewest" />
22+
</ItemGroup>
23+
1924
</Project>

src/CodeAnalysis/MetadataAnalyzer.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Immutable;
3-
using System.Diagnostics;
43
using Microsoft.CodeAnalysis;
54
using Microsoft.CodeAnalysis.Diagnostics;
65
using static ThisAssembly;
@@ -25,15 +24,6 @@ class Descriptors
2524
description: Strings.DefaultDescription.Description,
2625
helpLinkUri: "https://learn.microsoft.com/en-us/nuget/reference/nuspec#description");
2726

28-
public static readonly DiagnosticDescriptor LongDescription = new(
29-
Strings.LongDescription.ID,
30-
Strings.LongDescription.Title,
31-
Strings.LongDescription.Message,
32-
Category,
33-
DiagnosticSeverity.Error,
34-
true,
35-
helpLinkUri: "https://learn.microsoft.com/en-us/nuget/reference/nuspec#description");
36-
3727
public static readonly DiagnosticDescriptor MissingIcon = new(
3828
Strings.MissingIcon.ID,
3929
Strings.MissingIcon.Title,
@@ -122,11 +112,20 @@ class Descriptors
122112
true,
123113
description: SourceLinkEmbed.Description,
124114
helpLinkUri: "https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink");
115+
116+
public static readonly DiagnosticDescriptor DefaultAuthors = new(
117+
Strings.DefaultAuthors.ID,
118+
Strings.DefaultAuthors.Title,
119+
Strings.DefaultAuthors.Message,
120+
Category,
121+
DiagnosticSeverity.Warning,
122+
true,
123+
description: Strings.DefaultAuthors.Description,
124+
helpLinkUri: "https://learn.microsoft.com/en-us/nuget/reference/nuspec#authors");
125125
}
126126

127127
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
128128
Descriptors.DefaultDescription,
129-
Descriptors.LongDescription,
130129
Descriptors.MissingIcon,
131130
Descriptors.MissingReadme,
132131
Descriptors.MissingLicense,
@@ -135,7 +134,8 @@ class Descriptors
135134
Descriptors.MissingRepositoryUrl,
136135
Descriptors.MissingProjectUrl,
137136
Descriptors.MissingSourceLink,
138-
Descriptors.MissingSourceEmbed);
137+
Descriptors.MissingSourceEmbed,
138+
Descriptors.DefaultAuthors);
139139

140140
public override void Initialize(AnalysisContext context)
141141
{
@@ -157,13 +157,17 @@ public override void Initialize(AnalysisContext context)
157157
var sourceLinkEnabled = options.TryGetValue("build_property.EnableSourceLink", out var enableSLProp) &&
158158
"true".Equals(enableSLProp, StringComparison.OrdinalIgnoreCase);
159159

160-
if (options.TryGetValue("build_property.Description", out var description))
160+
if (options.TryGetValue("build_property.Description", out var description) &&
161+
description == DefaultDescription.DefaultValue)
162+
{
163+
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.DefaultDescription, null));
164+
}
165+
166+
if (options.TryGetValue("build_property.Authors", out var authors) &&
167+
options.TryGetValue("build_property.AssemblyName", out var assembly) &&
168+
authors == assembly)
161169
{
162-
if (description == DefaultDescription.DefaultValue)
163-
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.DefaultDescription, null));
164-
// There is really no way of getting such a long text in the diagnostic. We actually get an empty string.
165-
else if (description.Length > 4000)
166-
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.LongDescription, null));
170+
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.DefaultAuthors, null));
167171
}
168172

169173
string? packageIcon = default;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<ItemGroup>
4+
<CompilerVisibleProperty Include="IsPacking" />
5+
<CompilerVisibleProperty Include="PackageId" />
6+
<CompilerVisibleProperty Include="Description" />
7+
<CompilerVisibleProperty Include="PackageIcon" />
8+
<CompilerVisibleProperty Include="PackageIconUrl" />
9+
<CompilerVisibleProperty Include="PackageReadmeFile" />
10+
<CompilerVisibleProperty Include="PackageLicenseExpression" />
11+
<CompilerVisibleProperty Include="PackageLicenseFile" />
12+
<CompilerVisibleProperty Include="PackageLicenseUrl" />
13+
<CompilerVisibleProperty Include="SourceControlInformationFeatureSupported" />
14+
<CompilerVisibleProperty Include="RepositoryCommit" />
15+
<CompilerVisibleProperty Include="RepositoryUrl" />
16+
<CompilerVisibleProperty Include="PackageProjectUrl" />
17+
<CompilerVisibleProperty Include="EmbedUntrackedSources" />
18+
<CompilerVisibleProperty Include="EnableSourceLink" />
19+
20+
<CompilerVisibleProperty Include="Authors" />
21+
<CompilerVisibleProperty Include="AssemblyName" />
22+
</ItemGroup>
23+
24+
</Project>

src/CodeAnalysis/Resources.resx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@
132132
<data name="DefaultDescription_Title" xml:space="preserve">
133133
<value>Default description detected</value>
134134
</data>
135-
<data name="LongDescription_ID" xml:space="preserve">
136-
<value>NG0102</value>
137-
</data>
138-
<data name="LongDescription_Message" xml:space="preserve">
139-
<value>The Description property used for the package must be up to 4000 characters long.</value>
140-
</data>
141-
<data name="LongDescription_Title" xml:space="preserve">
142-
<value>Provided description is too long</value>
143-
</data>
144135
<data name="MissingIcon_Description" xml:space="preserve">
145136
<value>The PackageIcon project property can specify the path to a JPEG or PNG file to use as the package icon, which will be automatically packed properly.</value>
146137
</data>
@@ -246,4 +237,18 @@
246237
<data name="SourceLinkEmbed_Description" xml:space="preserve">
247238
<value>When EmbedUntrackedSources is set to 'true', Source Link will embed in your PDB the items that participated in the compile, but not are included in source control.</value>
248239
</data>
240+
<data name="DefaultAuthors_ID" xml:space="preserve">
241+
<value>NG0102</value>
242+
</data>
243+
<data name="DefaultAuthors_Title" xml:space="preserve">
244+
<value>Default authors detected</value>
245+
</data>
246+
<data name="DefaultAuthors_Message" xml:space="preserve">
247+
<value>Authors metadata matches the project's AssemblyName. The value should match the profile name(s) of the actual package author(s).</value>
248+
</data>
249+
<data name="DefaultAuthors_Description" xml:space="preserve">
250+
<value>Authors project property should contain a comma-separated list of packages authors, matching the profile names on nuget.org.
251+
These are displayed in the NuGet Gallery on nuget.org and are used to cross-reference packages by the same authors.</value>
252+
<comment>Long-form description</comment>
253+
</data>
249254
</root>

src/NuGetizer.Tasks/NuGetizer.Shared.targets

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Copyright (c) .NET Foundation. All rights reserved.
1717

1818
<!-- Adds compatibility targets with Pack SDK -->
1919
<Import Project="NuGetizer.Compatibility.props" />
20+
<!-- Adds CodeAnalysis props and items needed for diagnostics -->
21+
<Import Project="NuGetizer.CodeAnalysis.targets" />
2022

2123
<PropertyGroup>
2224
<!-- Whether to infer package contents -->
@@ -60,23 +62,6 @@ Copyright (c) .NET Foundation. All rights reserved.
6062
<ItemGroup>
6163
<!-- This is the capability that CPS in .NETStandard/.NETCore uses to enable the Pack context menu. Unify with that -->
6264
<ProjectCapability Include="Pack" Condition="'$(IsPackable)' == 'true'" />
63-
64-
<!-- Properties for the analyzers -->
65-
<CompilerVisibleProperty Include="IsPacking" />
66-
<CompilerVisibleProperty Include="PackageId" />
67-
<CompilerVisibleProperty Include="Description" />
68-
<CompilerVisibleProperty Include="PackageIcon" />
69-
<CompilerVisibleProperty Include="PackageIconUrl" />
70-
<CompilerVisibleProperty Include="PackageReadmeFile" />
71-
<CompilerVisibleProperty Include="PackageLicenseExpression" />
72-
<CompilerVisibleProperty Include="PackageLicenseFile" />
73-
<CompilerVisibleProperty Include="PackageLicenseUrl" />
74-
<CompilerVisibleProperty Include="SourceControlInformationFeatureSupported" />
75-
<CompilerVisibleProperty Include="RepositoryCommit" />
76-
<CompilerVisibleProperty Include="RepositoryUrl" />
77-
<CompilerVisibleProperty Include="PackageProjectUrl" />
78-
<CompilerVisibleProperty Include="EmbedUntrackedSources" />
79-
<CompilerVisibleProperty Include="EnableSourceLink" />
8065
</ItemGroup>
8166

8267
<!-- Extends the built-in GetTargetPathWithTargetPlatformMoniker output to signal that the project has been nugetized -->

0 commit comments

Comments
 (0)