The version of OpenSilver that you are referencing (1.0.0-alpha-007 or newer) requires migration of your project.

Your project is now referencing a version of OpenSilver that is newer and contains many improvements, but has some breaking changes which require migration of your project. To do that, simply follow the easy steps described below (or, alternatively, create a new project using the latest VSIX which contains updated project templates).

1. Open the .CSPROJ of the project that has the “.Browser” suffix, and make the following changes:

1.1. Find <TargetFramework>netstandard2.0</TargetFramework> and replace it with <TargetFramework>netstandard2.1</TargetFramework>

1.2. Find the block <PropertyGroup Label=”Globals”> and add the following code inside the block:
<NoXamlPreprocessor>True</NoXamlPreprocessor>
<OpenSilverType>2</OpenSilverType>

1.3. Find the “PackageReference” string and add the following additional package references:
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly” Version=”3.2.0″ />
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly.Build” Version=”3.2.0″ />
<PackageReference Include=”Microsoft.AspNetCore.Components.WebAssembly.DevServer” Version=”3.2.0″ />

2. Edit the file named “Index.razor” and add the following code to the end of the OnInitialized() method (inside the method, right before the closing curly brace):

Program.RunApplication();

3. Edit the file named “launchSettings.json” (located in the “Properties” sub-folder of the project with the “.Browser” suffix) and add the following line just under the “launchBrowser” setting (note: there are two places in the file where it should be added because the “launchBrowser” setting is present twice):

“inspectUri”: “{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}”,

4. Delete the file “Startup.cs” located in the project with the “.Browser” suffix.

5. Replace the content of “Program.cs” with the following code (and make sure to replace YOUR_APP_NAMESPACE):

				
					using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using DotNetForHtml5;

namespace YOUR_APP_NAMESPACE.Browser
{
    public class Program
    {
        public async static Task Main(string[] args)
        {
            Cshtml5Initializer.Initialize();
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("app");

            builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

            var host = builder.Build();
            await host.RunAsync();
        }

        public static void RunApplication()
        {
            Application.RunApplication(() =>
                {
                    var app = new YOUR_APP_NAMESPACE.App();
                });
        }
    }
}
				
			

When you have completed the steps above, restore the NuGet packages (by right-clicking on the solution in the Solution Explorer and clicking “Restore NuGet Packages”) and rebuild the solution.

Note: alternatively to the instructions above, you can create a new project using the latest VSIX which contains updated project templates.

Need help?

If you have any questions, please contact us at:

[email protected]

Shopping Basket