I created a blazor component library; when the project was created, it included scaffolded.cs and.js files with the names exampleJsInterop.
I also made a blazor app to test the component library by referencing it.
I created a nuget package of the component library today in order to install it in my blazor app. and I have immediately noticed that the exampleJsInterop is not working.
exampleJsInterop Implementation
public class exampleJsInterop : IAsyncDisposable
{
private readonly Lazy<Task<IJSObjectReference>> moduleTask;
public exampleJsInterop(IJSRuntime jsRuntime)
{
moduleTask = new (() => jsRuntime.InvokeAsync<IJSObjectReference>(
"import", "./_content/MyComponentProject/exampleJsInterop.js").AsTask());
}
}
Part of .Nuspec
<files>
<file src="bin\Debug\net7.0\MyComponentProject.dll" target="lib\net7.0" />
<file src="wwwroot\exampleJsInterop.js" target="wwwroot/MyComponentProject" />
<file src="wwwroot\exampleJsInterop.js" target="_content/MyComponentProject/exampleJsInterop.js"/>
</files>
Expectation: After implementing the above lines into the nuspec file I would expected to see the exampleJsInterop.js file under the wwwroot or _content but I do not.
and I get the following error messages when I try to invoke js methods from exampleJsInterop.js
Failed to load resource: the server responded with a status of 404 (Not Found)
Error: Microsoft.JSInterop.JSException: Failed to fetch dynamically imported module: https://localhost:13373/_content/MyComponentProject/exampleJsInterop.js
is there anything I'm doing wrong or missing with the nuspec file? any help with more experience is much appreciated.