Библиотеки классов Blazor - статические ресурсы недоступны в другом проекте
Я хочу создать пакет nuget.
Создаю тестовый проект библиотеки классов Blazor с именем TestBlazor.
Изменение стандартного компонента:
Component1.razor
@inject ExampleJsInterop js;
<div class="my-component">
This component is defined in the <strong>Test</strong> library.
</div>
@code{
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await js.Prompt("asasgg");
}
}
}
ExampleJsInterop.cs:
using Microsoft.JSInterop;
namespace TestBlazor
{
// This class provides an example of how JavaScript functionality can be wrapped
// in a .NET class for easy consumption. The associated JavaScript module is
// loaded on demand when first needed.
//
// This class can be registered as scoped DI service and then injected into Blazor
// components for use.
public class ExampleJsInterop : IAsyncDisposable
{
private readonly Lazy<Task<IJSObjectReference>> moduleTask;
public ExampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/TestBlazor/exampleJsInterop.js").AsTask());
}
public async ValueTask<string> Prompt(string message)
{
var module = await moduleTask.Value;
return await module.InvokeAsync<string>("showPrompt", message);
}
public async ValueTask DisposeAsync()
{
if (moduleTask.IsValueCreated)
{
var module = await moduleTask.Value;
await module.DisposeAsync();
}
}
}
}
Теперь я хочу вызвать свой компонент в другом решении:
Я подключаю его к проекту для тестирования:
и хочу использую:
builder.Services.AddTransient<TestBlazor.ExampleJsInterop>();
<TestBlazor.Component1></TestBlazor.Component1>
Получаю ошибку:
Microsoft.JSInterop.JSException: Failed to resolve module specifier 'https://localhost:7181/_content/TestBlazor/exampleJsInterop.js'
Пробовал решения с:
https://github.com/dotnet/aspnetcore/issues/13103
- Ничего не помогло
