# Use Legacy v4 SVG Icons with New Telerik UI for Blazor Versions

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>UI for Blazor</td>
        </tr>
        <tr>
            <td>Version</td>
            <td>16.0 and above</td>
        </tr>
    </tbody>
</table>

## Description

Telerik UI for Blazor **15.2.0** and older versions depend on `Telerik.SvgIcons` **4.x**. Telerik UI for Blazor **16.0.0** and newer versions depend on `Telerik.SvgIcons` **5.x**.

The icons in versions 4 and 5 use different styling. This article explains how to keep using old legacy v4 Telerik SVG icons after upgrading to Telerik UI for Blazor 16.0.0 or a newer version.

> The suggested algorithms in this article are not applicable to [apps that use Telerik font icons](https://www.telerik.com/blazor-ui/documentation/common-features/icons#set-global-blazor-icon-type). If you want to use v4 font icons with the latest Telerik UI for Blazor version, then load an old [font icon stylesheet](https://www.telerik.com/blazor-ui/documentation/common-features/icons#font-icon-stylesheet) instead:
>
> ```HTML.skip-repl
> <link rel="stylesheet" href="https://unpkg.com/@progress/kendo-font-icons@4.12.0/dist/index.css" />
> ```

## Solution

The app must use a modified version of the `Telerik.SvgIcons` v4 NuGet package. You can choose one of the following options:

* [Install a prebuilt NuGet package that is already available to download](https://www.telerik.com/blazor-ui/documentation/knowledge-base/icons-use-legacy-v4-svg-icons-with-new-telerik-ui-for-blazor-versions#use-prebuilt-svg-icon-nuget-package).
* [Build the package manually](https://www.telerik.com/blazor-ui/documentation/knowledge-base/icons-use-legacy-v4-svg-icons-with-new-telerik-ui-for-blazor-versions#create-custom-svg-icon-nuget-package).

### Use Prebuilt SVG Icon NuGet Package

1. Download the [`TelerikSvgIcons4.4.12.0.nupkg` NuGet package](https://github.com/telerik/blazor-ui/tree/master/icons/LegacyTelerikIcons). It packs a modified version of the [`Telerik.SvgIcons` project](https://github.com/telerik/kendo-icons/tree/develop/packages/svg-icons/src-cs/Telerik.SvgIcons) that is used to publish the [`Telerik.SvgIcons`](https://www.nuget.org/packages/Telerik.SvgIcons) NuGet package.
2. Add the `TelerikSvgIcons4` package to a [local NuGet feed](https://learn.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or another custom feed in your development and deployment environments.
3. Install the `TelerikSvgIcons4` package in your Blazor app.
   ```XML.skip-repl
   <ItemGroup>
       <PackageReference Include="Telerik.UI.for.Blazor" Version="16.*" />
       <PackageReference Include="TelerikSvgIcons4" Version="4.12.0" />
   </ItemGroup>
   ```
4. Add an [icon replacement service](https://www.telerik.com/blazor-ui/documentation/common-features/icons#change-default-svg-icons) to your Blazor app:
   ```C#.skip-repl
   using System;
   using System.Collections.Concurrent;
   using System.Reflection;
   using Telerik.Blazor.Services;
   using Telerik.SvgIcons;
   using TelerikSvgIcons4;

   namespace MyBlazorAppRootNamespace.Services;

   public class TelerikSvgIconsV4Service : ITelerikIconService
   {
       private static readonly ConcurrentDictionary<string, PropertyInfo?> Cache = new();

       public object? ReplaceIcon(IconInfo iconInfo)
       {
           var prop = Cache.GetOrAdd(iconInfo.IconName,
               name => typeof(SvgIcon4).GetProperty(name, BindingFlags.Public | BindingFlags.Static));
           return prop?.GetValue(null) as ISvgIcon;
       }
   }
   ```
5. Register the `TelerikSvgIconsV4Service` icon replacement service in `Program.cs` after the Telerik services:
   ```C#.skip-repl
   builder.Services.AddTelerikBlazor();
   builder.Services.AddSingleton<ITelerikIconService, TelerikSvgIconsV4Service>();
   ```
6. Add the `TelerikSvgIcons4` namespace to `_Imports.razor`:
   ```RAZOR.skip-repl
   @using Telerik.Blazor
   @using Telerik.Blazor.Components
   @using Telerik.SvgIcons

   @using TelerikSvgIcons4
   ```
7. At this point, all Telerik Blazor components that render SVG icons internally without public API control will switch to v4 icons.
8. If you need to display a v5 SVG icon, use a [`<TelerikSvgIcon>` component](https://www.telerik.com/blazor-ui/documentation/common-features/icons#svgicon-component):
   ```RAZOR.skip-repl
   <TelerikSvgIcon Icon="@SvgIcon.Bold" />
   ```

The [Sample App with v4 Telerik SVG Icons](https://github.com/telerik/blazor-ui/tree/master/icons/LegacyTelerikIcons) demonstrates all the above steps. The application includes both the `TelerikSvgIcons4.4.12.0.nupkg` NuGet package and its source code.

### Create Custom SVG Icon NuGet Package

The following algorithm describes how to create your own version of the [`TelerikSvgIcons4.4.12.0.nupkg` NuGet package](https://github.com/telerik/blazor-ui/tree/master/icons/LegacyTelerikIcons) with a name and icon set that suits your preferences. The main goal is to use the legacy icon package alongside the original `Telerik.SvgIcons` package without namespace and class name conflicts.

1. Clone the [`kendo-icons`](https://github.com/telerik/kendo-icons) GitHub repository.
2. Checkout the [`release-v4.x`](https://github.com/telerik/kendo-icons/tree/release-v4.x) branch.
3. All the following steps concern only the [`Telerik.SvgIcons`](https://github.com/telerik/kendo-icons/tree/develop/packages/svg-icons/src-cs/Telerik.SvgIcons) project inside the `kendo-icons/packages/svg-icons/src-cs/Telerik.SvgIcons` folder of the repository.
4. Delete the following files and folders:
   * `Models` folder—it contains the definitions for `SvgIconBase` and `ISvgIcon`, which will be reused from the original referenced `Telerik.SvgIcons` package.
   * `NOTICE.txt` file
   * `README.md` file
   * `Telerik.snk` file
5. Rename the `Telerik.SvgIcons` project folder and project file. This will also rename the project itself and the root namespace. This guide assumes the new project name is `TelerikSvgIcons4`.
6. Replace the `TelerikSvgIcons4.csproj` content. Use the latest `Telerik.SvgIcons` 4.x version or set one according to your preferences.
   ```XML.skip-repl
   <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
       <TargetFramework>netstandard2.0</TargetFramework>
       <PackageId>TelerikSvgIcons4</PackageId>
       <Version>4.12.0</Version>
       <NoWarn>$(NoWarn);CS0618</NoWarn>
   </PropertyGroup>
   <ItemGroup>
       <PackageReference Include="Telerik.SvgIcons" Version="4.12.0" />
   </ItemGroup>
   </Project>
   ```
7. Modify `SvgIcon.cs`:
   * Rename the file according to your preferences, for example, `SvgIcon4.cs`.
   * Rename the `SvgIcon` class in the file accordingly to `SvgIcon4`.
   * Change the `Telerik.SvgIcons` namespace to the root project namespace `TelerikSvgIcons4`
   * Add `using Telerik.SvgIcons;` in order to recognize the `ISvgIcon` interface from the original `Telerik.SvgIcons` package.
8. Modify all `.cs` files in the `Icons` folder:
   * Replace `namespace Telerik.SvgIcons` with `namespace TelerikSvgIcons4`
   * Add `using Telerik.SvgIcons;` in order to recognize the `SvgIconBase` class from the original `Telerik.SvgIcons` package.
9. Build and [pack](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack) the NuGet package:
   ```sh.skip-repl
   dotnet pack -c Release
   ```
10. Get the NuGet package and follow the steps from section [Use Prebuilt SVG Icon NuGet Package](https://www.telerik.com/blazor-ui/documentation/knowledge-base/icons-use-legacy-v4-svg-icons-with-new-telerik-ui-for-blazor-versions#use-prebuilt-svg-icon-nuget-package). Make sure that the `<Version>` in the `TelerikSvgIcons4.csproj` project file matches the version of the NuGet package reference in the consuming project.

The [Sample App with v4 Telerik SVG Icons](https://github.com/telerik/blazor-ui/tree/master/icons/LegacyTelerikIcons) includes a `TelerikSvgIcons4` project that already applies all the above steps.

## See Also

* [Sample App with v4 Telerik SVG Icons](https://github.com/telerik/blazor-ui/tree/master/icons/LegacyTelerikIcons)
* [Telerik Icons](https://www.telerik.com/blazor-ui/documentation/common-features/icons)
