Skip to content

Add SDKAnalysisLevel and UsingMicrosoftNETSdk to packageSpec#5833

Merged
Nigusu-Allehu merged 62 commits intodevfrom
dev-nyenework-sdk-analysis-level
Jul 12, 2024
Merged

Add SDKAnalysisLevel and UsingMicrosoftNETSdk to packageSpec#5833
Nigusu-Allehu merged 62 commits intodevfrom
dev-nyenework-sdk-analysis-level

Conversation

@Nigusu-Allehu
Copy link
Member

@Nigusu-Allehu Nigusu-Allehu commented May 30, 2024

Bug

Fixes: NuGet/Home#13309

Regression? Last working version:

Description

  • This PR follows Add a design for SdkAnalysisLevel dotnet/designs#308, to add SDKAnalysisLevel to NuGet.
  • The dotnet sdk installer sets the SDKAnalysisLevel value in Microsoft.NETCoreSdk.BundledVersions.props which is consumed early by msbuild. This is then consumed during restore.
  • This pr allows NuGet to read SdkAnalysisLevel and UsingMicrosoftNetSdk and have them ready in package spec of a project.

dotnet / msbuild

  • Since they use the RestoreTask task in NuGet.targets which calls src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs to get the dgspec content, update MsbuildRestoreUtility to get SdkAnalysisLevel and UsingMicrosoftNETSdk properties.

nuget.exe

  • Generates a temproary target file which will be used to generate a restore graph.
    •  * This PR adds a property in the dgspec being generated called SDKAnalysisLevel and UsingMicrosoftNETSdk which will then be consumed by nuget.exe restore command and then passed to the restore runner similar to dotnet /msbuild restore.
      the dgspec file would looks as follows
{
  "format": 1,
  "restore": {
    "C:\\demo\\hello\\hello\\hello.csproj": {}
  },
  "projects": {
    "C:\\demo\\hello\\hello\\hello.csproj": {
      "SDKAnalysisLevel": "9.0.100",
      "UsingMicrosoftNETSdk ": "true",
      "version": "1.0.0",
      "restore": {
        "projectUniqueName": "C:\\demo\\hello\\hello\\hello.csproj",
        "projectName": "hello",
        "projectPath": "C:\\demo\\hello\\hello\\hello.csproj",
        "packagesPath": "C:\\Nuget",
        "outputPath": "C:\\demo\\hello\\hello\\obj\\",
        "projectStyle": "PackageReference",
        "fallbackFolders": [
          "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
        ],
        "configFilePaths": [
          "C:\\Users\\nyenework\\AppData\\Roaming\\NuGet\\NuGet.Config",
          "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
          "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
        ],
        "originalTargetFrameworks": [
          "net8.0"
        ],
        "sources": {
          "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
          "C:\\Program Files\\dotnet\\library-packs": {},
          "https://api.nuget.org/v3/index.json": {}
        },
        "frameworks": {
          "net8.0": {
            "targetAlias": "net8.0",
            "projectReferences": {}
          }
        },
        "warningProperties": {
          "warnAsError": [
            "NU1605"
          ]
        },
        "restoreAuditProperties": {
          "enableAudit": "true",
          "auditLevel": "low",
          "auditMode": "direct"
        }
      },
      "frameworks": {
        "net8.0": {
          "targetAlias": "net8.0",
          "dependencies": {
            "Newtonsoft.Json": {
              "target": "Package",
              "version": "[13.0.3, )"
            },
            "System.Text.Json": {
              "target": "Package",
              "version": "[8.0.3, )"
            }
          },
          "imports": [
            "net461",
            "net462",
            "net47",
            "net471",
            "net472",
            "net48",
            "net481"
          ],
          "assetTargetFallback": true,
          "warn": true,
          "frameworkReferences": {
            "Microsoft.NETCore.App": {
              "privateAssets": "all"
            }
          },
          "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.301/PortableRuntimeIdentifierGraph.json"
        }
      }
    }
  }
}

VS

  • Get SdkAnalysisLevel and UsingMicrosoftNETSdk values and add them to the corresponding project packageSpec

PR Checklist

@Nigusu-Allehu Nigusu-Allehu requested a review from a team as a code owner May 30, 2024 22:54
@Nigusu-Allehu Nigusu-Allehu marked this pull request as draft May 30, 2024 22:54
@Nigusu-Allehu Nigusu-Allehu marked this pull request as ready for review June 4, 2024 04:03
@Nigusu-Allehu Nigusu-Allehu requested review from a team and nkolev92 June 4, 2024 04:04
@Nigusu-Allehu Nigusu-Allehu force-pushed the dev-nyenework-sdk-analysis-level branch from 578030c to 3594a62 Compare June 7, 2024 21:11
@Nigusu-Allehu Nigusu-Allehu changed the title Add SDKAnalysisLevel to NuGet Add SDKAnalysisLevel and UsingMicrosoftNETSdk to packageSpec Jun 13, 2024
@Nigusu-Allehu Nigusu-Allehu requested a review from zivkan June 14, 2024 06:39
@Nigusu-Allehu Nigusu-Allehu requested a review from jeffkl July 10, 2024 18:37
jeffkl
jeffkl previously approved these changes Jul 10, 2024
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments.

@Nigusu-Allehu Nigusu-Allehu requested review from jeffkl and nkolev92 July 11, 2024 21:31
jeffkl
jeffkl previously approved these changes Jul 11, 2024
nkolev92
nkolev92 previously approved these changes Jul 11, 2024
@Nigusu-Allehu Nigusu-Allehu requested review from jeffkl and nkolev92 July 11, 2024 22:57
zivkan
zivkan previously approved these changes Jul 11, 2024
Copy link
Member

@zivkan zivkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think there's scope for improvement, but nothing blocking.

@Nigusu-Allehu Nigusu-Allehu merged commit ecdbb79 into dev Jul 12, 2024
@Nigusu-Allehu Nigusu-Allehu deleted the dev-nyenework-sdk-analysis-level branch July 12, 2024 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority:1 PRs that are high priority and should be reviewed quickly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Roll-out new breaking change process for SDK tools, respect SdkAnalysisLevel

6 participants