-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn when dot missing from target framework strings
Fixes: NuGet/Home#9215
- Loading branch information
Showing
16 changed files
with
273 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/NuGet.Core/NuGet.Common/PublicAPI/net45/PublicAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NuGet.Common.NuGetLogCode.NU1010 = 1010 -> NuGet.Common.NuGetLogCode | ||
NuGet.Common.NuGetLogCode.NU1011 = 1011 -> NuGet.Common.NuGetLogCode | ||
NuGet.Common.NuGetLogCode.NU5501 = 5501 -> NuGet.Common.NuGetLogCode |
2 changes: 1 addition & 1 deletion
2
src/NuGet.Core/NuGet.Common/PublicAPI/net472/PublicAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
NuGet.Common.NuGetLogCode.NU1010 = 1010 -> NuGet.Common.NuGetLogCode | ||
NuGet.Common.NuGetLogCode.NU1011 = 1011 -> NuGet.Common.NuGetLogCode | ||
|
||
NuGet.Common.NuGetLogCode.NU5501 = 5501 -> NuGet.Common.NuGetLogCode |
2 changes: 1 addition & 1 deletion
2
src/NuGet.Core/NuGet.Common/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
NuGet.Common.NuGetLogCode.NU1010 = 1010 -> NuGet.Common.NuGetLogCode | ||
NuGet.Common.NuGetLogCode.NU1011 = 1011 -> NuGet.Common.NuGetLogCode | ||
|
||
NuGet.Common.NuGetLogCode.NU5501 = 5501 -> NuGet.Common.NuGetLogCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
static NuGet.Packaging.Rules.AnalysisResources.InvalidUndottedFrameworkWarning.get -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
static NuGet.Packaging.Rules.AnalysisResources.InvalidUndottedFrameworkWarning.get -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
static NuGet.Packaging.Rules.AnalysisResources.InvalidUndottedFrameworkWarning.get -> string |
9 changes: 9 additions & 0 deletions
9
src/NuGet.Core/NuGet.Packaging/Rules/AnalysisResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/NuGet.Core/NuGet.Packaging/Rules/InvalidUndottedFrameworkRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Linq; | ||
using NuGet.Client; | ||
using NuGet.Common; | ||
using NuGet.ContentModel; | ||
using NuGet.Frameworks; | ||
using NuGet.Packaging.Core; | ||
using NuGet.RuntimeModel; | ||
|
||
namespace NuGet.Packaging.Rules | ||
{ | ||
internal class InvalidUndottedFrameworkRule : IPackageRule | ||
{ | ||
public string MessageFormat { get; } | ||
|
||
public InvalidUndottedFrameworkRule(string messageFormat) | ||
{ | ||
MessageFormat = messageFormat; | ||
} | ||
|
||
public IEnumerable<PackagingLogMessage> Validate(PackageArchiveReader builder) | ||
{ | ||
var set = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
foreach (var file in builder.GetFiles().Select(t => PathUtility.GetPathWithDirectorySeparator(t))) | ||
{ | ||
set.Add(file); | ||
} | ||
|
||
var managedCodeConventions = new ManagedCodeConventions(new RuntimeGraph()); | ||
var collection = new ContentItemCollection(); | ||
collection.Load(set.Select(path => path.Replace('\\', '/')).ToArray()); | ||
|
||
var patterns = managedCodeConventions.Patterns; | ||
|
||
var frameworkPatterns = new List<PatternSet>() | ||
{ | ||
patterns.RuntimeAssemblies, | ||
patterns.CompileRefAssemblies, | ||
patterns.CompileLibAssemblies, | ||
patterns.NativeLibraries, | ||
patterns.ResourceAssemblies, | ||
patterns.MSBuildFiles, | ||
patterns.ContentFiles, | ||
patterns.ToolsAssemblies, | ||
patterns.EmbedAssemblies, | ||
patterns.MSBuildTransitiveFiles | ||
}; | ||
var warnPaths = new HashSet<string>(); | ||
|
||
foreach (var pattern in frameworkPatterns) | ||
{ | ||
IEnumerable<ContentItemGroup> targetedItemGroups = ContentExtractor.GetContentForPattern(collection, pattern); | ||
foreach (ContentItemGroup group in targetedItemGroups) | ||
{ | ||
foreach (ContentItem item in group.Items) | ||
{ | ||
var frameworkString = (string)item.Properties["tfm_raw"]; | ||
var framework = (NuGetFramework)item.Properties["tfm"]; | ||
if (framework == null) | ||
{ | ||
continue; | ||
} | ||
|
||
if (framework.Version.Major >= 5 && | ||
StringComparer.OrdinalIgnoreCase.Equals(FrameworkConstants.FrameworkIdentifiers.NetCoreApp, framework.Framework)) | ||
{ | ||
var dotIndex = frameworkString.IndexOf('.'); | ||
var dashIndex = frameworkString.IndexOf('-'); | ||
var frameworkVersionHasDots = (dashIndex > -1 && dotIndex > -1 && dotIndex < dashIndex) || (dashIndex == -1 && dotIndex > -1); | ||
if (!frameworkVersionHasDots) | ||
{ | ||
warnPaths.Add(item.Path); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var output = new List<PackagingLogMessage>(); | ||
|
||
if (warnPaths.Count > 0) | ||
{ | ||
output.Add(CreatePackageIssue(string.Join(", ", warnPaths))); | ||
} | ||
|
||
return output; | ||
} | ||
|
||
private PackagingLogMessage CreatePackageIssue(string target) | ||
{ | ||
return PackagingLogMessage.CreateWarning( | ||
string.Format(CultureInfo.CurrentCulture, MessageFormat, target), | ||
NuGetLogCode.NU5501); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters