BlazorJSInterop.SourceGenerator 6.0.10

dotnet add package BlazorJSInterop.SourceGenerator --version 6.0.10
NuGet\Install-Package BlazorJSInterop.SourceGenerator -Version 6.0.10
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorJSInterop.SourceGenerator" Version="6.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorJSInterop.SourceGenerator --version 6.0.10
#r "nuget: BlazorJSInterop.SourceGenerator, 6.0.10"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlazorJSInterop.SourceGenerator as a Cake Addin
#addin nuget:?package=BlazorJSInterop.SourceGenerator&version=6.0.10

// Install BlazorJSInterop.SourceGenerator as a Cake Tool
#tool nuget:?package=BlazorJSInterop.SourceGenerator&version=6.0.10

BlazorJSInterop

This is a Blazor library that uses .NET source generators in order to create implementations of JS Service files and include them into the dependency injection collection.

Using the library

  1. Include the source generator as a dependency into your Blazor project file.
dotnet add package BlazorJSInterop.SourceGenerator --version 6.0.10
  1. Prototype your service interfaces using the BlazorJSInteropSource attribute in the interface and the BlazorJSInteropMethod attributes in all its methods. All methods in the interfaces must return ValueTask or ValueTask<T> and all the method attributes must include the JS name function as a parameter.

For example:

[BlazorJSInteropSource]
public interface IJSService
{
    [BlazorJSInteropMethod("showHelloWorldAlert")]
    ValueTask ShowHelloWorldAlert();

    [BlazorJSInteropMethod("showNamePrompt")]
    ValueTask<string> ShowNamePrompt(string title);

    [BlazorJSInteropMethod("showNameAlert")]
    ValueTask ShowNameAlert(string name);
}
  1. In your Program.cs file include the following using statement:
using BlazorJSInterop.SourceGenerator.Extensions;
  1. In your Main method in Program.cs include the following line builder.AddJSInteropImplementations(Assembly.GetExecutingAssembly()); such as:
public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);

    // Add this line to register the generated code into the dependency injection collection.
    builder.AddJSInteropImplementations(Assembly.GetExecutingAssembly());

    builder.RootComponents.Add<App>("app");

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

    await builder.Build().RunAsync();
}
  1. Inject your interface into any of your files as you would do with any other service.

Testing the library locally as a project reference

  1. If you want to test this project locally as a project reference, it is important to keep ReferenceOutputAssembly to true as there are some dependencies of this assembly that will be needed in your project.
<ProjectReference Include="..\..\src\BlazorJSInterop.SourceGenerator\BlazorJSInterop.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.10 438 10/12/2022
6.0.9 436 9/14/2022
6.0.8 396 8/21/2022
6.0.7 400 8/5/2022
6.0.6 433 7/10/2022
6.0.5 440 5/24/2022
6.0.4 437 4/13/2022
6.0.3 431 3/28/2022
6.0.2 435 2/13/2022
6.0.2-RC1 128 2/12/2022
6.0.1 282 12/22/2021
6.0.1-RC1 151 12/21/2021
6.0.0 268 12/21/2021
6.0.0-RC2 155 12/20/2021
6.0.0-RC1 655 12/1/2021
1.0.0 506 1/5/2021
0.1.0 365 12/15/2020

Align with version 6.0.10