1

I have many solutions, and each solution has many projects. Some projects may be used in multiple solutions.

The ASP.NET MVC web app is targetting .NET 4.7.1. The API and library project both target .NET 4.7.1 and .NET 4.6. The ASP.NET MVC web app and the API reference the library project.

I migrated the API and Library to .NET 8.0 and it works.

There are many NuGet packages referenced in this solution which are deprecated, vulnerable and old versions. So I try updated all the Nuget packages to the latest version, but found challenges.

Some Nuget packages in their latest version are not compatible with .NET 4.7.1, so those are not getting installed.

Since the library project targets both .NET 4.7.1 and .NET 8.0, I don't know whether to update such nuget packages, and need advise here.

Can I convert this library to a .NET Standard project that is compatible with both .NET 4.7.1 and .NET 8.0 ? If I do that, can I update the NuGet packages to their latest versions, since it is not targeting .NET 4.7.1 but it should work with the ASP.NET MVC web app which is on .NET 4.7.1.

Or should I refactor the code which uses that NuGet package when converting to .NET Standard ?

The question is not specific to any particular NuGet package, since there are many NuGet packages, and need advise.

Please advise.

1
  • If your library project has references with are all available for a .NET Standard project, then this would be the easiest path. If that's not the case - then you might need to create two versions of your library project Commented Jul 16, 2024 at 6:20

1 Answer 1

0

It depends on few things, but for the most NuGet packages that you use you can convert them to target .netstandard2.0 and they will be compatible with .Net8 and .NET 4.7.1.

Biggest issue here if your NuGet packages have dependencies that are not compatible with .netstandard2.0 and they are framework specific.

For example you have in you library a package that is compatible with .NET4.7.1 - and have replacement that targets .NET8 then you should have a NuGet with multitarget frameworks:

 <TargetFrameworks>net8.0;net4.7.1</TargetFrameworks>

and in code use directives to implement diffent packages and have different packages as dependecies.

For example:

    <ItemGroup Condition="'$(targetframework)'=='net6.0'">
        <PackageReference Include="SkiaSharp" Version="2.88.6" />
        <PackageReference Include="System.Drawing.Common" Version="8.0.1" />
    </ItemGroup>
    <ItemGroup Condition="'$(targetframework)'=='net8.0'">
        <PackageReference Include="SkiaSharp" Version="2.88.6" />
        <PackageReference Include="System.Drawing.Common" Version="8.0.1" />
    </ItemGroup>
  <ItemGroup Condition="'$(targetframework)'=='net48'">
    <Reference Include="System.Net" />
    <Reference Include="System.Net.Http" />
  </ItemGroup>

and in code it would be something like this:

#if NET6_0_OR_GREATER
using SkiaSharp;
#endif
#if NET48
using System.Drawing;
#endif

namespace SomeNameSpace;

public class SomeClass
{
  #if NET6_0_OR_GREATER
        public SKImage Image { get; set; }
#endif
#if NET48
        public Image Image { get; set; }
#endif
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot J.Memisevic for the input. I am updating Nuget package which is compatible to both.
There are 150 NuGet Package and some are Vulnerable, Some are Deprecated and most of the are not latest. I am updating NuGet Package one by one and see any incompatible issue arises. if any issue comes then I do revert that package and check whether app works. some time it is not working, so i have to do from beginning. Please advise best approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.