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

NSwag.Commands: Microsoft.Extensions.PlatformAbstractions Is Deprecated #5117

Open
lieven121 opened this issue Mar 3, 2025 · 1 comment
Open

Comments

@lieven121
Copy link

Describe the bug

Microsoft.Extensions.PlatformAbstractions is deprecated
https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/platformabstractions-package-removed

This package also has sub dependencies with vulnerabilities

Image

Version used

14.2.0

Notes
Might help
System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute()

but you need to extract the version manually

Image

I would create a PR that replaces the 2 lines of code (and extracts the version) but I am not sure if I understand the implications.
and the whole, substring the version might not be that good.

The file impacted would be
RuntimeUtilities

//-----------------------------------------------------------------------
// <copyright file="RuntimeUtilities.cs" company="NSwag">
//     Copyright (c) Rico Suter. All rights reserved.
// </copyright>
// <license>https://github.com/RicoSuter/NSwag/blob/master/LICENSE.md</license>
// <author>Rico Suter, [email protected]</author>
//-----------------------------------------------------------------------

#if !NETFRAMEWORK
using System.Reflection;
using System.Runtime.Versioning;
using System.Globalization;
#endif



namespace NSwag.Commands
{
    /// <summary>Provides runtime utilities.</summary>
    public class RuntimeUtilities
    {
        /// <summary>Gets the current runtime.</summary>
        public static Runtime CurrentRuntime
        {
            get
            {
#if NETFRAMEWORK
                return IntPtr.Size == 4 ? Runtime.WinX86 : Runtime.WinX64;
#else
                var target = Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>();

                if (target == null || !target.FrameworkName.StartsWith(".NETCoreApp", StringComparison.OrdinalIgnoreCase))
	                return IntPtr.Size == 4 ? Runtime.WinX86 : Runtime.WinX64;

                var version = target.FrameworkName.Substring(target.FrameworkName.IndexOf("Version=v", StringComparison.OrdinalIgnoreCase) + 9);
                var majorV = int.Parse(version.Split('.')[0], CultureInfo.InvariantCulture);

                if(majorV >= 9)
	                return Runtime.Net90;

                return Runtime.Net80;
#endif
            }
        }
    }
}
@lahma
Copy link
Collaborator

lahma commented Mar 3, 2025

#5058

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants