From 9f5cc4b7c20f79cfaa3fc2a1c6b36cb6337da340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 15 Jul 2024 18:27:43 +0200 Subject: [PATCH] Don't use obsolete X509Certificate2 ctor --- .../src/PublishArtifactsInManifest.cs | 4 ++++ .../src/AkaMSLinksBase.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs b/src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs index e1dccfad738..86c1958c4c2 100644 --- a/src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs +++ b/src/Microsoft.DotNet.Build.Tasks.Feed/src/PublishArtifactsInManifest.cs @@ -352,7 +352,11 @@ internal PublishArtifactsInManifestBase ConstructPublishingV3Task(BuildModel bui SkipSafetyChecks = this.SkipSafetyChecks, AkaMSClientId = this.AkaMSClientId, AkaMSClientCertificate = !string.IsNullOrEmpty(AkaMSClientCertificate) ? +#if NET9_0_OR_GREATER + X509CertificateLoader.LoadPkcs12(Convert.FromBase64String(File.ReadAllText(AkaMSClientCertificate)), password: null) : null, +#else new X509Certificate2(Convert.FromBase64String(File.ReadAllText(AkaMSClientCertificate))) : null, +#endif AkaMSCreatedBy = this.AkaMSCreatedBy, AkaMSGroupOwner = this.AkaMSGroupOwner, AkaMsOwners = this.AkaMsOwners, diff --git a/src/Microsoft.DotNet.Deployment.Tasks.Links/src/AkaMSLinksBase.cs b/src/Microsoft.DotNet.Deployment.Tasks.Links/src/AkaMSLinksBase.cs index 013ea538c98..77a64125333 100644 --- a/src/Microsoft.DotNet.Deployment.Tasks.Links/src/AkaMSLinksBase.cs +++ b/src/Microsoft.DotNet.Deployment.Tasks.Links/src/AkaMSLinksBase.cs @@ -24,7 +24,11 @@ protected AkaMSLinkManager CreateAkaMSLinksManager() AkaMSLinkManager manager; if (!string.IsNullOrEmpty(ClientCertificate)) { +#if NET9_0_OR_GREATER + manager = new AkaMSLinkManager(ClientId, X509CertificateLoader.LoadPkcs12(Convert.FromBase64String(File.ReadAllText(ClientCertificate)), password: null), Tenant, Log); +#else manager = new AkaMSLinkManager(ClientId, new X509Certificate2(Convert.FromBase64String(File.ReadAllText(ClientCertificate))), Tenant, Log); +#endif } else if (!string.IsNullOrEmpty(ClientSecret)) {