Skip to content

Commit 214b162

Browse files
authored
Merge pull request #9272 from NuGet/dev
[ReleasePrep][2022.10.05] RI of dev into main
2 parents 94499fd + 5e27c1e commit 214b162

File tree

13 files changed

+155
-108
lines changed

13 files changed

+155
-108
lines changed

CodeQL.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
path_classifiers:
2+
library:
3+
# The default behavior is to tag library code as `library`. Results are hidden
4+
# for library code. You can tag further files as being library code by adding them
5+
# to the `library` section.
6+
- "src/NuGetGallery/Scripts/gallery/moment-*.js"

src/DatabaseMigrationTools/DatabaseMigrationTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<PrivateAssets>all</PrivateAssets>
6666
</PackageReference>
6767
<PackageReference Include="NuGet.Services.Validation">
68-
<Version>2.105.0</Version>
68+
<Version>2.106.0</Version>
6969
</PackageReference>
7070
</ItemGroup>
7171
<ItemGroup>

src/GitHubVulnerabilities2Db/GitHubVulnerabilities2Db.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<Version>4.3.0-dev-5590084</Version>
9292
</PackageReference>
9393
<PackageReference Include="NuGet.Services.Cursor">
94-
<Version>2.105.0</Version>
94+
<Version>2.106.0</Version>
9595
</PackageReference>
9696
</ItemGroup>
9797
<ItemGroup>

src/NuGetGallery.Core/NuGetGallery.Core.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<Version>6.0.0</Version>
5151
</PackageReference>
5252
<PackageReference Include="NuGet.Services.FeatureFlags">
53-
<Version>2.105.0</Version>
53+
<Version>2.106.0</Version>
5454
</PackageReference>
5555
<PackageReference Include="WindowsAzure.Storage">
5656
<Version>9.3.3</Version>
@@ -59,13 +59,13 @@
5959

6060
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
6161
<PackageReference Include="NuGet.Services.Messaging.Email">
62-
<Version>2.105.0</Version>
62+
<Version>2.106.0</Version>
6363
</PackageReference>
6464
<PackageReference Include="NuGet.Services.Validation">
65-
<Version>2.105.0</Version>
65+
<Version>2.106.0</Version>
6666
</PackageReference>
6767
<PackageReference Include="NuGet.Services.Validation.Issues">
68-
<Version>2.105.0</Version>
68+
<Version>2.106.0</Version>
6969
</PackageReference>
7070
<PackageReference Include="NuGet.StrongName.elmah.corelibrary">
7171
<Version>1.2.2</Version>
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using NuGet.Client;
9+
using NuGet.ContentModel;
10+
using NuGet.Frameworks;
11+
using NuGet.Packaging.Core;
12+
using NuGet.RuntimeModel;
13+
14+
namespace NuGetGallery
15+
{
16+
public static class AssetFrameworkHelper
17+
{
18+
/// <summary>
19+
/// This method combines the logic used in restore operations to make a determination about the TFM supported by the package.
20+
/// We have curated a set of compatibility requirements for our needs in NuGet.org. The client logic can be found here:
21+
/// https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs#L252-L294
22+
/// https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs#L439-L442
23+
/// ...and our combination of these elements is below.
24+
/// The logic is essentially this:
25+
/// - Determine whether we're looking at a tools package. In this case we will use tools "pattern sets" (collections of file patterns
26+
/// defined in <see cref="ManagedCodeConventions" />) to assess which frameworks are targeted by the package.
27+
/// - If this isn't a tools package, we look for build-time, runtime, content and resource file patterns
28+
/// For added details on the various cases, see unit tests targeting this method.
29+
/// </summary>
30+
public static IEnumerable<NuGetFramework> GetAssetFrameworks(string packageId, IReadOnlyList<PackageType> packageTypes, IList<string> packageFiles)
31+
{
32+
var supportedTFMs = Enumerable.Empty<NuGetFramework>();
33+
if (packageFiles != null && packageFiles.Any())
34+
{
35+
// Setup content items for analysis
36+
var items = new ContentItemCollection();
37+
items.Load(packageFiles);
38+
var runtimeGraph = new RuntimeGraph();
39+
var conventions = new ManagedCodeConventions(runtimeGraph);
40+
41+
// Let's test for tools packages first--they're a special case
42+
var groups = Enumerable.Empty<ContentItemGroup>();
43+
if (packageTypes.Count == 1 && (packageTypes[0] == PackageType.DotnetTool ||
44+
packageTypes[0] == PackageType.DotnetCliTool))
45+
{
46+
// Only a package that is a tool package (and nothing else) will be matched against tools pattern set
47+
groups = items.FindItemGroups(conventions.Patterns.ToolsAssemblies);
48+
}
49+
else
50+
{
51+
// Gather together a list of pattern sets indicating the kinds of packages we wish to evaluate
52+
var patterns = new[]
53+
{
54+
conventions.Patterns.CompileRefAssemblies,
55+
conventions.Patterns.CompileLibAssemblies,
56+
conventions.Patterns.RuntimeAssemblies,
57+
conventions.Patterns.ContentFiles,
58+
conventions.Patterns.ResourceAssemblies,
59+
};
60+
61+
// Add MSBuild to this list, but we need to ensure we have package assets before they make the cut.
62+
// A series of files in the right places won't matter if there's no {id}.props|targets.
63+
var msbuildPatterns = new[]
64+
{
65+
conventions.Patterns.MSBuildFiles,
66+
conventions.Patterns.MSBuildMultiTargetingFiles,
67+
};
68+
69+
// We'll create a set of "groups" --these are content items which satisfy file pattern sets
70+
var standardGroups = patterns
71+
.SelectMany(p => items.FindItemGroups(p));
72+
73+
// Filter out MSBuild assets that don't match the package ID and append to groups we already have
74+
var msbuildGroups = msbuildPatterns
75+
.SelectMany(p => items.FindItemGroups(p))
76+
.Where(g => HasBuildItemsForPackageId(g.Items, packageId));
77+
groups = standardGroups.Concat(msbuildGroups);
78+
}
79+
80+
// Now that we have a collection of groups which have made it through the pattern set filter, let's transform them into TFMs
81+
supportedTFMs = groups
82+
.SelectMany(p => p.Properties)
83+
.Where(pair => pair.Key == ManagedCodeConventions.PropertyNames.TargetFrameworkMoniker)
84+
.Select(pair => pair.Value)
85+
.Cast<NuGetFramework>()
86+
.Distinct();
87+
}
88+
89+
return supportedTFMs;
90+
}
91+
92+
private static bool HasBuildItemsForPackageId(IEnumerable<ContentItem> items, string packageId)
93+
{
94+
foreach (var item in items)
95+
{
96+
var fileName = Path.GetFileName(item.Path);
97+
if (fileName == PackagingCoreConstants.EmptyFolder)
98+
{
99+
return true;
100+
}
101+
102+
if ($"{packageId}.props".Equals(fileName, StringComparison.OrdinalIgnoreCase))
103+
{
104+
return true;
105+
}
106+
107+
if ($"{packageId}.targets".Equals(fileName, StringComparison.OrdinalIgnoreCase))
108+
{
109+
return true;
110+
}
111+
}
112+
113+
return false;
114+
}
115+
116+
/// <summary>
117+
/// Framework Generation shortname identifiers used by the Search Service for framework filtering.
118+
/// </summary>
119+
public static class FrameworkGenerationIdentifiers
120+
{
121+
public const string Net = "net";
122+
123+
public const string NetFramework = "netframework";
124+
125+
public const string NetCoreApp = "netcoreapp";
126+
127+
public const string NetStandard = "netstandard";
128+
}
129+
}
130+
}

src/NuGetGallery.Services/NuGetGallery.Services.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@
8888
<Version>6.0.0</Version>
8989
</PackageReference>
9090
<PackageReference Include="NuGet.Services.Configuration">
91-
<Version>2.105.0</Version>
91+
<Version>2.106.0</Version>
9292
</PackageReference>
9393
<PackageReference Include="NuGet.Services.Logging">
94-
<Version>2.105.0</Version>
94+
<Version>2.106.0</Version>
9595
</PackageReference>
9696
<PackageReference Include="NuGet.StrongName.WebBackgrounder">
9797
<Version>0.2.0</Version>

src/NuGetGallery.Services/PackageManagement/PackageService.cs

Lines changed: 3 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -712,104 +712,14 @@ public virtual IEnumerable<NuGetFramework> GetSupportedFrameworks(PackageArchive
712712
return package.GetSupportedFrameworks();
713713
}
714714

715-
/// <summary>
716-
/// This method combines the logic used in restore operations to make a determination about the TFM supported by the package.
717-
/// We have curated a set of compatibility requirements for our needs in NuGet.org. The client logic can be found here:
718-
/// https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs#L252-L294
719-
/// https://github.com/NuGet/NuGet.Client/blob/63255047fe7052cc33b763356ff995d9166f719e/src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs#L439-L442
720-
/// ...and our combination of these elements is below.
721-
/// The logic is essentially this:
722-
/// - Determine whether we're looking at a tools package. In this case we will use tools "pattern sets" (collections of file patterns
723-
/// defined in <see cref="ManagedCodeConventions" />) to assess which frameworks are targeted by the package.
724-
/// - If this isn't a tools package, we look for build-time, runtime, content and resource file patterns
725-
/// For added details on the various cases, see unit tests targeting this method.
726-
/// </summary>
727715
public virtual IEnumerable<NuGetFramework> GetSupportedFrameworks(NuspecReader nuspecReader, IList<string> packageFiles)
728716
{
729-
var supportedTFMs = Enumerable.Empty<NuGetFramework>();
730-
if (packageFiles != null && packageFiles.Any() && nuspecReader != null)
731-
{
732-
// Setup content items for analysis
733-
var items = new ContentItemCollection();
734-
items.Load(packageFiles);
735-
var runtimeGraph = new RuntimeGraph();
736-
var conventions = new ManagedCodeConventions(runtimeGraph);
737-
738-
// Let's test for tools packages first--they're a special case
739-
var groups = Enumerable.Empty<ContentItemGroup>();
740-
var packageTypes = nuspecReader.GetPackageTypes();
741-
if (packageTypes.Count == 1 && (packageTypes[0] == PackageType.DotnetTool ||
742-
packageTypes[0] == PackageType.DotnetCliTool))
743-
{
744-
// Only a package that is a tool package (and nothing else) will be matched against tools pattern set
745-
groups = items.FindItemGroups(conventions.Patterns.ToolsAssemblies);
746-
}
747-
else
748-
{
749-
// Gather together a list of pattern sets indicating the kinds of packages we wish to evaluate
750-
var patterns = new[]
751-
{
752-
conventions.Patterns.CompileRefAssemblies,
753-
conventions.Patterns.CompileLibAssemblies,
754-
conventions.Patterns.RuntimeAssemblies,
755-
conventions.Patterns.ContentFiles,
756-
conventions.Patterns.ResourceAssemblies,
757-
};
758-
759-
// Add MSBuild to this list, but we need to ensure we have package assets before they make the cut.
760-
// A series of files in the right places won't matter if there's no {id}.props|targets.
761-
var msbuildPatterns = new[]
762-
{
763-
conventions.Patterns.MSBuildFiles,
764-
conventions.Patterns.MSBuildMultiTargetingFiles,
765-
};
766-
767-
// We'll create a set of "groups" --these are content items which satisfy file pattern sets
768-
var standardGroups = patterns
769-
.SelectMany(p => items.FindItemGroups(p));
770-
771-
// Filter out MSBuild assets that don't match the package ID and append to groups we already have
772-
var packageId = nuspecReader.GetId();
773-
var msbuildGroups = msbuildPatterns
774-
.SelectMany(p => items.FindItemGroups(p))
775-
.Where(g => HasBuildItemsForPackageId(g.Items, packageId));
776-
groups = standardGroups.Concat(msbuildGroups);
777-
}
778-
779-
// Now that we have a collection of groups which have made it through the pattern set filter, let's transform them into TFMs
780-
supportedTFMs = groups
781-
.SelectMany(p => p.Properties)
782-
.Where(pair => pair.Key == ManagedCodeConventions.PropertyNames.TargetFrameworkMoniker)
783-
.Select(pair => pair.Value)
784-
.Cast<NuGetFramework>()
785-
.Distinct();
786-
}
787-
788-
return supportedTFMs;
789-
}
790-
791-
private static bool HasBuildItemsForPackageId(IEnumerable<ContentItem> items, string packageId)
792-
{
793-
foreach (var item in items)
717+
if (nuspecReader != null)
794718
{
795-
var fileName = Path.GetFileName(item.Path);
796-
if (fileName == PackagingCoreConstants.EmptyFolder)
797-
{
798-
return true;
799-
}
800-
801-
if ($"{packageId}.props".Equals(fileName, StringComparison.OrdinalIgnoreCase))
802-
{
803-
return true;
804-
}
805-
806-
if ($"{packageId}.targets".Equals(fileName, StringComparison.OrdinalIgnoreCase))
807-
{
808-
return true;
809-
}
719+
return AssetFrameworkHelper.GetAssetFrameworks(nuspecReader.GetId(), nuspecReader.GetPackageTypes(), packageFiles);
810720
}
811721

812-
return false;
722+
return Enumerable.Empty<NuGetFramework>();
813723
}
814724

815725
private static EmbeddedLicenseFileType GetEmbeddedLicenseType(PackageMetadata packageMetadata)

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,13 +2244,13 @@
22442244
<Version>1.4.0</Version>
22452245
</PackageReference>
22462246
<PackageReference Include="NuGet.Services.Licenses">
2247-
<Version>2.105.0</Version>
2247+
<Version>2.106.0</Version>
22482248
</PackageReference>
22492249
<PackageReference Include="NuGet.Services.Owin">
2250-
<Version>2.105.0</Version>
2250+
<Version>2.106.0</Version>
22512251
</PackageReference>
22522252
<PackageReference Include="NuGet.Services.Sql">
2253-
<Version>2.105.0</Version>
2253+
<Version>2.106.0</Version>
22542254
</PackageReference>
22552255
<PackageReference Include="Owin">
22562256
<Version>1.0.0</Version>

src/NuGetGallery/Scripts/gallery/autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
}
188188

189189
function jquerySafeId(id) {
190-
return id.replace(/\./g, "\\.");
190+
return jQuery.escapeSelector(id);
191191
}
192192

193193
function safeId(id) {

src/NuGetGallery/Services/CertificateService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public async Task<Certificate> AddCertificateAsync(HttpPostedFileBase file)
6060
certificate = new Certificate()
6161
{
6262
#pragma warning disable CS0618 // Only set the SHA1 thumbprint, for backwards compatibility. Never read it.
63+
// CodeQL [SM02196] Only set the SHA1 thumbprint, for backwards compatibility. Never read it.
6364
Sha1Thumbprint = certificateFile.Sha1Thumbprint,
6465
#pragma warning restore CS0618
6566
Thumbprint = certificateFile.Sha256Thumbprint,

0 commit comments

Comments
 (0)