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

Add SDKAnalysisLevel and UsingMicrosoftNETSdk to packageSpec #5833

Merged
merged 62 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
df13d8a
Add SDKAnalysisLevel to RestoreTask
Nigusu-Allehu May 30, 2024
a749b2a
Cleanup
Nigusu-Allehu May 30, 2024
4f1a349
Consume default value of SDKAnalysis from Microsoft.NETCoreSdk.Bundle…
Nigusu-Allehu Jun 4, 2024
4b4fcf8
white space
Nigusu-Allehu Jun 4, 2024
d481b82
nuget.exe sdkanalysislevel impelementation
Nigusu-Allehu Jun 7, 2024
64fccd0
clean up
Nigusu-Allehu Jun 7, 2024
ead8da1
clean up
Nigusu-Allehu Jun 7, 2024
c23bcec
VS sdkAnalysisLevel
Nigusu-Allehu Jun 11, 2024
95dd2a1
Get SdkAnalysis to restore args
Nigusu-Allehu Jun 12, 2024
ea797eb
remove unnecssary sdkanalysislevel
Nigusu-Allehu Jun 12, 2024
7fe801e
cleanup
Nigusu-Allehu Jun 12, 2024
b064808
add using dotnet sdk attribute
Nigusu-Allehu Jun 13, 2024
f9e77d1
Add to sdkanalysislevel to packageSpec only
Nigusu-Allehu Jun 13, 2024
06d83d5
clean up
Nigusu-Allehu Jun 13, 2024
c1a0719
Write to dgspec file
Nigusu-Allehu Jun 13, 2024
b93567d
rebase
Nigusu-Allehu Jun 13, 2024
61e1d2e
make UsingSdk value nullable
Nigusu-Allehu Jun 13, 2024
2e6977e
Clis and legacy projects
Nigusu-Allehu Jun 13, 2024
9a683e8
Read sdkanalysislevel for legacy
Nigusu-Allehu Jun 13, 2024
7c86e9f
clean up
Nigusu-Allehu Jun 13, 2024
22c1cda
static graph restore
Nigusu-Allehu Jun 14, 2024
2163b7e
Address comments
Nigusu-Allehu Jun 14, 2024
3a20e1e
white space
Nigusu-Allehu Jun 14, 2024
3665ac3
handle null value
Nigusu-Allehu Jun 14, 2024
897cf47
merge coflict
Nigusu-Allehu Jun 14, 2024
2eed02e
white space
Nigusu-Allehu Jun 14, 2024
3e42b7f
Use bool
Nigusu-Allehu Jun 16, 2024
64031fb
ci build
Nigusu-Allehu Jun 17, 2024
a65c1df
Make usre usingSDK value passed correctly
Nigusu-Allehu Jun 20, 2024
5dcc9cd
empty sdk analysis
Nigusu-Allehu Jun 20, 2024
9440a93
read dgspec and default true
Nigusu-Allehu Jun 21, 2024
00c19ac
move sdkAnalysisLevel and UsingMicrosoftNetSdk to restoremetadata
Nigusu-Allehu Jun 21, 2024
2894f73
address null metadata
Nigusu-Allehu Jun 21, 2024
2250f2f
Read values from lock file
Nigusu-Allehu Jun 23, 2024
f14454a
test packagespec and packageSpecWriter
Nigusu-Allehu Jun 24, 2024
4581135
GetPackageSpec test
Nigusu-Allehu Jun 24, 2024
44d8be6
throw excpetion when reading invalid project properties
Nigusu-Allehu Jun 24, 2024
4037ec3
cealnup
Nigusu-Allehu Jun 25, 2024
6072d35
Throw exception when parsing sdkAnalysisLevel from dgspec file
Nigusu-Allehu Jul 1, 2024
8b4ab6a
add tests
Nigusu-Allehu Jul 1, 2024
f1efd29
address comments
Nigusu-Allehu Jul 4, 2024
eec8f14
extract GetSdkAnalysisLevel
Nigusu-Allehu Jul 9, 2024
4f95b37
cleanup
Nigusu-Allehu Jul 9, 2024
dfb8051
test
Nigusu-Allehu Jul 9, 2024
4933379
test nominations
Nigusu-Allehu Jul 9, 2024
a49d3d4
Legacy projects cleanup
Nigusu-Allehu Jul 9, 2024
2eee675
formatting
Nigusu-Allehu Jul 10, 2024
c6395a4
whitespace
Nigusu-Allehu Jul 10, 2024
2b7aefb
Address comments
Nigusu-Allehu Jul 10, 2024
5d87d7d
cleanup
Nigusu-Allehu Jul 10, 2024
726e924
cleanup
Nigusu-Allehu Jul 10, 2024
610ef4e
address comments
Nigusu-Allehu Jul 10, 2024
62ccf94
cleanup
Nigusu-Allehu Jul 10, 2024
ee8551b
;
Nigusu-Allehu Jul 10, 2024
aeee5ce
remove unnecessary resources
Nigusu-Allehu Jul 10, 2024
9ec39b3
address comments
Nigusu-Allehu Jul 11, 2024
2d46254
Merge branch 'dev' into dev-nyenework-sdk-analysis-level
Nigusu-Allehu Jul 11, 2024
ab708ca
write if true only
Nigusu-Allehu Jul 11, 2024
0a3be7f
default false everywhere
Nigusu-Allehu Jul 11, 2024
3b70648
Fix tests
Nigusu-Allehu Jul 11, 2024
19a9c0e
Rename method
Nigusu-Allehu Jul 11, 2024
32dcbfb
write if false only
Nigusu-Allehu Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ private async Task<PackageSpec> GetPackageSpecAsync(ISettings settings)
string centralPackageTransitivePinningEnabled = GetPropertySafe(_vsProjectAdapter.BuildProperties, ProjectBuildProperties.CentralPackageTransitivePinningEnabled);
// Do not add new properties here. Use BuildProperties.GetPropertyValue instead, without DTE fallback.
#pragma warning restore CS0618 // Type or member is obsolete
string skdAnalysisLevelString = _vsProjectAdapter.BuildProperties.GetPropertyValue(ProjectBuildProperties.SdkAnalysisLevel);
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
string usingNetSdk = _vsProjectAdapter.BuildProperties.GetPropertyValue(ProjectBuildProperties.UsingMicrosoftNETSdk);
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved

return new PackageSpec(tfis)
{
Expand Down Expand Up @@ -555,6 +557,8 @@ private async Task<PackageSpec> GetPackageSpecAsync(ISettings settings)
CentralPackageFloatingVersionsEnabled = MSBuildStringUtility.IsTrue(_vsProjectAdapter.BuildProperties.GetPropertyValue(ProjectBuildProperties.CentralPackageFloatingVersionsEnabled)),
CentralPackageTransitivePinningEnabled = MSBuildStringUtility.IsTrue(centralPackageTransitivePinningEnabled),
RestoreAuditProperties = auditProperties,
SdkAnalysisLevel = MSBuildRestoreUtility.GetSdkAnalysisLevel(skdAnalysisLevelString),
UsingMicrosoftNETSdk = MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(usingNetSdk),
}
};
}
Expand Down

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
Expand Up @@ -289,4 +289,10 @@
<value>Error occurred while getting package vulnerability data: {0}</value>
<comment>{0} is an error message</comment>
</data>
<data name="Invalid_AttributeValue" xml:space="preserve">
<value>The {0} value: `{1}` is invalid. Valid example: `{2}`</value>
<comment>{0} - is the attribute
{1} is the invalid value of the attribute.
{2} a valid attriibute value example</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -712,5 +712,30 @@ private static string[] HandleClear(string[] input)

return input;
}

internal static NuGetVersion? GetSdkAnalysisLevel(IReadOnlyList<IVsTargetFrameworkInfo4> targetFrameworks)
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
{
string? skdAnalysisLevelString = GetSingleNonEvaluatedPropertyOrNull(targetFrameworks, nameof(ProjectBuildProperties.SdkAnalysisLevel), v => v) ?? string.Empty;
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
NuGetVersion? sdkAnalysisLevel = null;

if (skdAnalysisLevelString is not null)
{
sdkAnalysisLevel = MSBuildRestoreUtility.GetSdkAnalysisLevel(skdAnalysisLevelString);
}

return sdkAnalysisLevel;
}

internal static bool GetUsingMicrosoftNETSdk(IReadOnlyList<IVsTargetFrameworkInfo4> targetFrameworks)
{
string? usingNetSdk = GetSingleNonEvaluatedPropertyOrNull(targetFrameworks, nameof(ProjectBuildProperties.UsingMicrosoftNETSdk), v => v);

if (usingNetSdk is not null)
{
return MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(usingNetSdk);
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,11 @@ internal static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectR
CentralPackageVersionOverrideDisabled = VSNominationUtilities.IsCentralPackageVersionOverrideDisabled(targetFrameworks),
CentralPackageTransitivePinningEnabled = VSNominationUtilities.IsCentralPackageTransitivePinningEnabled(targetFrameworks),
RestoreAuditProperties = VSNominationUtilities.GetRestoreAuditProperties(targetFrameworks),
SdkAnalysisLevel = VSNominationUtilities.GetSdkAnalysisLevel(targetFrameworks),
UsingMicrosoftNETSdk = VSNominationUtilities.GetUsingMicrosoftNETSdk(targetFrameworks),
},
RuntimeGraph = VSNominationUtilities.GetRuntimeGraph(targetFrameworks),
RestoreSettings = new ProjectRestoreSettings() { HideWarningsAndErrors = true }
RestoreSettings = new ProjectRestoreSettings() { HideWarningsAndErrors = true },
};

return packageSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,9 @@ private PackageSpec GetPackageSpec(IMSBuildProject project, IReadOnlyDictionary<
restoreMetadata.RestoreLockProperties = new RestoreLockProperties(project.GetProperty("RestorePackagesWithLockFile"), project.GetProperty("NuGetLockFilePath"), project.IsPropertyTrue("RestoreLockedMode"));
restoreMetadata.Sources = GetSources(project, innerNodes, settings);
restoreMetadata.TargetFrameworks = GetProjectRestoreMetadataFrameworkInfos(targetFrameworkInfos, projectsByTargetFramework);

restoreMetadata.UsingMicrosoftNETSdk = MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(project.GetProperty("UsingMicrosoftNETSdk"));
NuGetVersion skdAnalysisLevel = MSBuildRestoreUtility.GetSdkAnalysisLevel(project.GetProperty("SdkAnalysisLevel"));
restoreMetadata.SdkAnalysisLevel = skdAnalysisLevel ?? restoreMetadata.SdkAnalysisLevel;
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
return (restoreMetadata, targetFrameworkInfos);

static (ProjectStyle, string packagesConfigPath) GetProjectStyle(IMSBuildProject project, IReadOnlyDictionary<string, IMSBuildProject> tfms, Common.ILogger log)
Expand Down
2 changes: 2 additions & 0 deletions src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<NuGetAudit>$(NuGetAudit)</NuGetAudit>
<NuGetAuditLevel>$(NuGetAuditLevel)</NuGetAuditLevel>
<NuGetAuditMode>$(NuGetAuditMode)</NuGetAuditMode>
<SdkAnalysisLevel>$(SdkAnalysisLevel)</SdkAnalysisLevel>
kartheekp-ms marked this conversation as resolved.
Show resolved Hide resolved
<UsingMicrosoftNETSdk>$(UsingMicrosoftNETSdk)</UsingMicrosoftNETSdk>
</_RestoreGraphEntry>
</ItemGroup>

Expand Down
9 changes: 9 additions & 0 deletions src/NuGet.Core/NuGet.Build.Tasks/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/NuGet.Core/NuGet.Build.Tasks/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,10 @@
<value>An error occurred starting static graph-based restore. {0}. Please file an issue at https://github.com/NuGet/Home</value>
<comment>0 - The exception message</comment>
</data>
</root>
<data name="Invalid_AttributeValue" xml:space="preserve">
<value>The {0} value: `{1}` is invalid. Valid example: `{2}`</value>
<comment>{0} - is the attribute
{1} is the invalid value of the attribute.
{2} a valid attriibute value example</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ NuGet.Commands.UpdateSourceArgs.AllowInsecureConnections.set -> void
NuGet.Commands.UpdateSourceArgs.AllowInsecureConnections.get -> bool
NuGet.Commands.AddSourceArgs.AllowInsecureConnections.set -> void
NuGet.Commands.AddSourceArgs.AllowInsecureConnections.get -> bool
~static NuGet.Commands.MSBuildRestoreUtility.GetSdkAnalysisLevel(string sdkAnalysisLevel) -> NuGet.Versioning.NuGetVersion
~static NuGet.Commands.MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(string usingMicrosoftNETSdk) -> bool
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ NuGet.Commands.UpdateSourceArgs.AllowInsecureConnections.set -> void
NuGet.Commands.UpdateSourceArgs.AllowInsecureConnections.get -> bool
NuGet.Commands.AddSourceArgs.AllowInsecureConnections.set -> void
NuGet.Commands.AddSourceArgs.AllowInsecureConnections.get -> bool
~static NuGet.Commands.MSBuildRestoreUtility.GetSdkAnalysisLevel(string sdkAnalysisLevel) -> NuGet.Versioning.NuGetVersion
~static NuGet.Commands.MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(string usingMicrosoftNETSdk) -> bool
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ NuGet.Commands.UpdateSourceArgs.AllowInsecureConnections.set -> void
NuGet.Commands.UpdateSourceArgs.AllowInsecureConnections.get -> bool
NuGet.Commands.AddSourceArgs.AllowInsecureConnections.set -> void
NuGet.Commands.AddSourceArgs.AllowInsecureConnections.get -> bool
~static NuGet.Commands.MSBuildRestoreUtility.GetSdkAnalysisLevel(string sdkAnalysisLevel) -> NuGet.Versioning.NuGetVersion
~static NuGet.Commands.MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(string usingMicrosoftNETSdk) -> bool
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ public static PackageSpec GetPackageSpec(IEnumerable<IMSBuildItem> items)
result.RestoreMetadata.CentralPackageVersionOverrideDisabled = isCentralPackageVersionOverrideDisabled;
result.RestoreMetadata.CentralPackageFloatingVersionsEnabled = isCentralPackageFloatingVersionsEnabled;
result.RestoreMetadata.CentralPackageTransitivePinningEnabled = isCentralPackageTransitivePinningEnabled;
result.RestoreMetadata.UsingMicrosoftNETSdk = MSBuildRestoreUtility.GetUsingMicrosoftNETSdk(specItem.GetProperty("UsingMicrosoftNETSdk"));
result.RestoreMetadata.SdkAnalysisLevel = MSBuildRestoreUtility.GetSdkAnalysisLevel(specItem.GetProperty("SdkAnalysisLevel")) ?? result.RestoreMetadata.SdkAnalysisLevel;
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved
}

return result;
Expand Down Expand Up @@ -941,6 +943,40 @@ public static RestoreAuditProperties GetRestoreAuditProperties(IMSBuildItem spec
return null;
}

public static NuGetVersion GetSdkAnalysisLevel(string sdkAnalysisLevel)
{
if (!string.IsNullOrEmpty(sdkAnalysisLevel))
{
if (NuGetVersion.TryParse(sdkAnalysisLevel, out NuGetVersion version))
{
return version;
}
else
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Invalid_AttributeValue, "SdkAnalysisLevel", sdkAnalysisLevel, "9.0.100"));
}
}

return null;
}
Nigusu-Allehu marked this conversation as resolved.
Show resolved Hide resolved

public static bool GetUsingMicrosoftNETSdk(string usingMicrosoftNETSdk)
{
if (!string.IsNullOrEmpty(usingMicrosoftNETSdk))
{
if (bool.TryParse(usingMicrosoftNETSdk, out var result))
{
return result;
}
else
{
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Invalid_AttributeValue, "UsingMicrosoftNETSdk", usingMicrosoftNETSdk, "false"));
}
}

return false;
}

private static HashSet<string> GetAuditSuppressions(IEnumerable<IMSBuildItem> items)
{
IEnumerable<string> suppressions = GetItemByType(items, "NuGetAuditSuppress")
Expand Down
9 changes: 9 additions & 0 deletions src/NuGet.Core/NuGet.Commands/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.Commands/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1121,4 +1121,10 @@ NuGet requires HTTPS sources. Please refer to https://aka.ms/nuget-https-everywh
NuGet requires HTTPS sources. Please refer to https://aka.ms/nuget-https-everywhere for more information.</value>
<comment>{0} - list of server URIs</comment>
</data>
<data name="Invalid_AttributeValue" xml:space="preserve">
<value>The {0} value: `{1}` is invalid. Valid example: `{2}`</value>
<comment>{0} - is the attribute
{1} is the invalid value of the attribute.
{2} a valid attriibute value example</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ public static class ProjectBuildProperties
public const string NuGetAuditLevel = nameof(NuGetAuditLevel);
public const string NuGetAuditMode = nameof(NuGetAuditMode);
public const string CentralPackageFloatingVersionsEnabled = nameof(CentralPackageFloatingVersionsEnabled);
public const string SdkAnalysisLevel = nameof(SdkAnalysisLevel);
public const string UsingMicrosoftNETSdk = nameof(UsingMicrosoftNETSdk);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
~const NuGet.ProjectManagement.ProjectBuildProperties.SdkAnalysisLevel = "SdkAnalysisLevel" -> string
~const NuGet.ProjectManagement.ProjectBuildProperties.UsingMicrosoftNETSdk = "UsingMicrosoftNETSdk" -> string
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public partial class JsonPackageSpecReader
private static readonly byte[] HashTagImportPropertyName = Encoding.UTF8.GetBytes("#import");
private static readonly byte[] ProjectReferencesPropertyName = Encoding.UTF8.GetBytes("projectReferences");
private static readonly byte[] EmptyStringPropertyName = Encoding.UTF8.GetBytes(string.Empty);
private static readonly byte[] SdkAnalysisLevel = Encoding.UTF8.GetBytes("SdkAnalysisLevel");
private static readonly byte[] UsingMicrosoftNETSdk = Encoding.UTF8.GetBytes("UsingMicrosoftNETSdk");

internal static PackageSpec GetPackageSpecUtf8JsonStreamReader(Stream stream, string name, string packageSpecPath, IEnvironmentVariableReader environmentVariableReader, string snapshotValue = null)
{
Expand Down Expand Up @@ -945,6 +947,8 @@ private static void ReadMSBuildMetadata(ref Utf8JsonStreamReader jsonReader, Pac
RestoreAuditProperties auditProperties = null;
bool useMacros = MSBuildStringUtility.IsTrue(environmentVariableReader.GetEnvironmentVariable(MacroStringsUtility.NUGET_ENABLE_EXPERIMENTAL_MACROS));
var userSettingsDirectory = NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
bool usingMicrosoftNetSdk = true;
NuGetVersion sdkAnalysisLevel = null;

if (jsonReader.Read() && jsonReader.TokenType == JsonTokenType.StartObject)
{
Expand Down Expand Up @@ -1169,6 +1173,32 @@ private static void ReadMSBuildMetadata(ref Utf8JsonStreamReader jsonReader, Pac

warningProperties = new WarningProperties(warnAsError, noWarn, allWarningsAsErrors, warningsNotAsErrors);
}
else if (jsonReader.ValueTextEquals(UsingMicrosoftNETSdk))
{
usingMicrosoftNetSdk = jsonReader.ReadNextTokenAsBoolOrTrue(UsingMicrosoftNETSdk);
}
else if (jsonReader.ValueTextEquals(SdkAnalysisLevel))
{
string sdkAnalysisLevelString = jsonReader.ReadNextTokenAsString();

if (!string.IsNullOrEmpty(sdkAnalysisLevelString))
{
try
{
sdkAnalysisLevel = new NuGetVersion(sdkAnalysisLevelString);
}
catch (ArgumentException ex)
{
throw new ArgumentException(
string.Format(CultureInfo.CurrentCulture,
Strings.Invalid_AttributeValue,
Encoding.UTF8.GetString(SdkAnalysisLevel),
sdkAnalysisLevelString,
"9.0.100"),
ex);
}
}
}
else
{
jsonReader.Skip();
Expand All @@ -1193,6 +1223,8 @@ private static void ReadMSBuildMetadata(ref Utf8JsonStreamReader jsonReader, Pac
msbuildMetadata.CentralPackageVersionOverrideDisabled = centralPackageVersionOverrideDisabled;
msbuildMetadata.CentralPackageTransitivePinningEnabled = CentralPackageTransitivePinningEnabled;
msbuildMetadata.RestoreAuditProperties = auditProperties;
msbuildMetadata.SdkAnalysisLevel = sdkAnalysisLevel;
msbuildMetadata.UsingMicrosoftNETSdk = usingMicrosoftNetSdk;

if (configFilePaths != null)
{
Expand Down
Loading