Sunday, 3 August 2025

How to upgrade .NET CORE

 How to upgrade .NET CORE using Visual Studio

Upgrading to a new .NET Core version involves multiple steps to ensure your development environment, source code, continuous integration (CI), and hosting environment are all appropriately updated. Below are detailed instructions to guide you through the process.



Reasons to upgrade:

  • The current .NET version is no longer supported.
  • The new version supports a new operating system.
  • The new version includes important API, performance, or security features.

 Step 1: Upgrade the development environment

The first step in the upgrade process is to ensure your development environment is ready for the new .NET version. The .NET SDK, which includes the .NET CLI, build system, and runtime, needs to be updated.

  1. Download the installer: Visit the .NET download page and download the installer for your operating system.
  2. Run the installer: Follow the on-screen instructions to install the new .NET SDK.
  3. Use package manager (optional): Some operating systems allow installation via a package manager (e.g., Homebrew for macOS, apt-get for Linux).
  4. Visual Studio users: If you use Visual Studio, upgrade to the latest version of Visual Studio, which will automatically include the latest .NET SDK.

Verify installation:

Open a command-line interface and run the following commands to ensure the new SDK is installed:

dotnet –list-sdks

dotnet –list-runtimes

Step 2: Upgrade source code

Next, you must update your project files to target the new .NET version.

  1. Open the project file: Locate and open your project file (e.g., *.csproj, *.vbproj, or *.fsproj).
  2. Update TargetFramework: Change the <TargetFramework> property value to the new version. For example:

<TargetFramework>net6.0</TargetFramework>

to

<TargetFramework>net8.0</TargetFramework>

  1. Use upgrade assistant: The .NET Upgrade Assistant tool can automate these changes.
  2. Build the project: Rebuild your project using the new SDK. The command-line command for this is:

dotnet build

  1. Restore workloads: If needed, restore workloads with the new SDK version using:

dotnet workload restore

Step 3: Update continuous integration (CI)

Ensure your CI pipeline is updated to use the new .NET SDK. Update the configuration files for your CI system (e.g., GitHub Actions, Azure Pipelines) to reference the new .NET version.

  1. Modify configuration files: Update the .NET version in your CI configuration files to match the new version.
  2. Run CI pipelines: Execute your CI pipelines to verify that the build and test processes work correctly with the new .NET version.



Step 4: Update hosting environment

Lastly, update your hosting environment to support the new .NET version. This step ensures that your production environment can run the upgraded application.

  1. Install new .NET runtime: Ensure the hosting environment has the new .NET Runtime installed. This might involve updating server configurations or using container images with the latest runtime.

Deploy application: Deploy your upgraded application to the hosting environment and verify that it runs correctly.



Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------

How to Check .NET Core Versions

 

What is the latest version of .NET Core?






.NET Core versioning scheme

The .NET Core versioning scheme follows a structured approach, which is essential for maintaining clarity and consistency across its releases. This scheme is crucial given the platform’s broad use for developing cloud-native, cross-platform, and IoT applications.

Major, minor, patch overview:

  • Major version: Incremented annually, this version signals significant product changes, including new features, API-breaking changes, and major dependency updates. Notably, even-numbered major versions like .NET 6 and .NET 8 are long-term supported (LTS), providing three years of support. In contrast, odd-numbered versions receive standard-term support (STS) with 18 months of updates.
  • Minor version: Increased when new behaviors or public APIs are introduced, along with non-breaking enhancements, this increment may also reflect the adoption of a newer minor version of an existing dependency.
  • Patch version: Adjusted for bug fixes, new platform support, or minor updates in dependencies. It represents maintenance updates that do not alter the API surface area or introduce new features.

The .NET Runtime adheres to semantic versioning (SemVer), denoted as MAJOR.MINOR.PATCH[-PRERELEASE-BUILDNUMBER]. This method ensures each version number clearly communicates the extent and nature of changes, aiding developers in understanding the impact of upgrades.



LTS (Long-Term Support):

Long-Term Support (LTS) versions of .NET Core are designed to provide extended stability and support. These versions are released every two years and offer three years of free support and patches.

LTS versions are typically even-numbered (e.g., .NET 6, .NET 8) and are essential for environments where long-term stability and reliability are critical. LTS versions are often chosen for enterprise applications due to their extended maintenance window, ensuring that applications remain secure and stable without frequent major updates.

Benefits of LTS:

  • Stability: Provides a reliable and consistent environment over an extended period.
  • Extended Support: Offers a three-year support window with patches and updates.
  • Reduced Risk: Minimizes disruptions from major changes and breaking updates.


LTS (Long-Term Support):

Long-Term Support (LTS) versions of .NET Core are designed to provide extended stability and support. These versions are released every two years and offer three years of free support and patches.

LTS versions are typically even-numbered (e.g., .NET 6, .NET 8) and are essential for environments where long-term stability and reliability are critical. LTS versions are often chosen for enterprise applications due to their extended maintenance window, ensuring that applications remain secure and stable without frequent major updates.

Benefits of LTS:

  • Stability: Provides a reliable and consistent environment over an extended period.
  • Extended Support: Offers a three-year support window with patches and updates.
  • Reduced Risk: Minimizes disruptions from major changes and breaking updates.

How to Check .NET Core Versions


To check the currently installed .NET Core SDK version, use this command:

dotnet –version

This will immediately show you the exact version of .NET Core you are currently running.

You can also use the command:

–list-sdks

To see which SDKs are installed and their locations on your machine.



Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------


Thursday, 22 May 2025

Migrating from a .NET developer role to a Java developer role

Hello Everyone,

 I worked as a .NET full stack developer for almost 15 years, but recently I started working on Java technology so Migrating from a .NET developer role to a Java developer role involves both technical and mindset shifts.


 Here's a structured guide to help you make the transition smoothly


1. Understand the Core Differences

Both Java and C# are the same, but there are some core differences
Aspect.NETJava
Primary LanguageC#Java
RuntimeCLR (Common Language Runtime)JVM (Java Virtual Machine)
Framework.NET Framework / .NET CoreSpring, Jakarta EE, etc.
IDEVisual StudioIntelliJ IDEA, Eclipse, VS Code
Build ToolsMSBuildMaven, Gradle

2. Learn Java Syntax and Ecosystem

Since C# and Java are syntactically similar, the learning curve is manageable.  I focused on:

  • Java syntax and conventions
  • Exception handling
  • Collections framework
  • Java 8+ features (Streams, Lambdas, Optional, etc.)
  • Memory management and garbage collection

🧰 3. Get Comfortable with Java Tools

I started working with the following tools

  • IDE: IntelliJ IDEA 
  • Build Tools: Maven or Gradle
  • Dependency Management: Understand pom.xml (Maven) or build.gradle
  • Testing: JUnit, Mockito

🌐 4. Learn Java Frameworks

I started learning below frameworks

  • Spring Boot: For building REST APIs and microservices
  • Spring Data JPA: For database access
  • Spring Security: For authentication and authorization

🗃️ 5. Database and ORM

I know Entity Framework in .NET, so I learned:

  • JPA (Java Persistence API)
  • Hibernate (most popular JPA implementation)

🧪 6. Practice with Projects

I build small projects like:

  • A RESTful API with Spring Boot
  • A CRUD application using Spring Data JPA
  • A microservice with Spring Cloud

📦 7. Understand Java Deployment

I had good knowledge of .NET Core Deployment so I learned
  • WAR vs JAR files
  • Running Java apps with java -jar
  • Dockerizing Java applications

📈 8. Explore Advanced Topics (Optional)

  • Reactive programming with Spring WebFlux
  • Kafka or RabbitMQ for messaging
  • Kubernetes for deployment

It took me almost 2 months to learn Java from .NET, but it was a good experience.

Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------





Thursday, 30 January 2025

How to register multiple implementations of the same interface

 In a recent project, I faced an issue while registering multiple implementations of the same interface in .NET CORE. I found different solutions for multiple implementations of the same interface in .NET CORE


I faced an issue with the below. I have 3 classes with 1 interface


public interface IService { }
public class ServiceA : IService { }
public class ServiceB : IService { } 
public class ServiceC : IService { }


 In ASP.NET Core, how do I register these services and resolve them at runtime based on some key?



Solution 1: Use of Microsoft.Extensions.DependencyInjection.


Register your services as:


services.AddSingleton<IService, ServiceA>();

services.AddSingleton<IService, ServiceB>();

services.AddSingleton<IService, ServiceC>();



Then resolve with a little of Linq:


var services = serviceProvider.GetServices<IService>();

var serviceB = services.First(o => o.GetType() == typeof(ServiceB));

or


var serviceZ = services.First(o => o.Name.Equals("Z"));



Solution 2:   use of inheritance


Create a separate interface derived from the Base interface for each class.  create individual interfaces that inherit from IService, implement the inherited interfaces in your IService implementations, and register the inherited interfaces rather than the base.

In this way  we can have as many copies of the interface as we want and we can pick suitable names for each of them. And we have the benefit of type safety


public interface IService 

{

}


public interface IServiceA: IService

{}


public interface IServiceB: IService

{}


public interface IServiceC: IService

{}


public class ServiceA: IServiceA 

{}


public class ServiceB: IServiceB

{}


public class ServiceC: IServiceC

{}



Container:


container.Register<IServiceA, ServiceA>();

container.Register<IServiceB, ServiceB>();

container.Register<IServiceC, ServiceC>();




Solution 3 : Use of .NET CORE 8  Keyed DI services


Keyed DI services

Keyed dependency injection (DI) services provides a means for registering and retrieving DI services using keys. By using keys, you can scope how you register and consume services. These are some of the new APIs:


 Don’t forget to leave your feedback and comments below!

Regards

Sujeet Bhujbal

--------------------------------------------------------------------------------

Blog: www.sujeetbhujbal.com 

CodeProject:-https://www.codeproject.com/Members/SujitBhujbal

CsharpCorner:-http://www.c-sharpcorner.com/Authors/sujit9923/sujit-bhujbal.aspx

Linkedin :-http://in.linkedin.com/in/sujitbhujbal  

Medium: - https://medium.com/@SujeetBhujbal

------------------------------------------------------------------------------