aws / aws-toolkit-visual-studio

AWS Toolkit for Visual Studio - a plugin to interact with AWS
https://aws.amazon.com/visualstudio/
Apache License 2.0
111 stars 29 forks source link

Package up WASM for @rendermode InteractiveWebAssembly Razor components #413

Closed genifycom closed 7 months ago

genifycom commented 7 months ago

In Visual Studio, DotNet 8, create a "Blazor Web App" with Interactive render mode WebAssembly say BlazorWebApp1.

This will create two projects. A web project and a client Webassembly project.

Next create a Lambda Application project for a Web API with Razor pages. Adding the component directory from the Blazor Web App and register these in Startup.cs

services.AddRazorComponents() .AddInteractiveWebAssemblyComponents();

and

endpoints.MapRazorComponents();

the Lambda Application will now run Blazor using "Server Side Rendering". This deploys and runs in Lambda as expected.

Now we add the project dependency for the BlazorWebApp1.Client project for the interactive Webassembly components.

Locally the Lambda Application run fine. Publish to AWS Lambda, however, gets an error because it fails to know how to package up the WASM component.

ERROR: The dotnet publish command return unsuccessful error code
Error packaging up project in C:\Dev\yyy\CSRInLambda\CSRServerless\. for CloudFormation resource AspNetCoreFunction: ERROR: The dotnet publish command return unsuccessful error code

What we should get is an _framework directory under wwwroot with all the WASM DLLs and the BlazorWebApp1.Client.wasm file.

This will then allow us to serve up the WASM component to the client (note, no Blazor server, just WASM).

Firstly, what changes can I make to the AWS Toolkit for Visual Studio to get this to work.

Secondly, can the toolkit be adjusted to handle this vital configuration where we can run Razor Pages and Razor components (both server-side which already works, and Webassembly interactive).

I am totally willing to do some work with this, I just don't know where to start.

If you need a sample project, please advise.

Thanks, Dave

genifycom commented 7 months ago

Can anyone help with this?

Proj file is the following:

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <AWSProjectType>Lambda</AWSProjectType>

        <!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
        <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

        <!-- Generate ready to run images during publishing to improve cold start time. -->
        <PublishReadyToRun>false</PublishReadyToRun>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
        <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.3" />
        <ProjectReference Include="..\CSRInLambda\CSRInLambda.Client\CSRInLambda.Client.csproj" />
    </ItemGroup>
    <ItemGroup>
        <Folder Include="wwwroot\images\" />
    </ItemGroup>
</Project>

It will publish locally but not to AWS

genifycom commented 7 months ago

I am going to transfer this from a feature request to a bug because there is a problem publishing what should work.