### Build and run on Linux Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/DotNetOnWebWorkersReact/README.md Builds and runs the full sample on Linux. The long version runs `dotnet publish`, `npm install`, `npm run integrate`, `npm run build`, and `npm run start`; the short version from the React directory uses `npm run build:all:debug`. ```bash # builds the dotnet project, creating build artifacts in dist/dotnet dotnet publish -c Debug ./dotnet/QRGenerator.csproj cd react # installs node packages: npm install # cleans the previous dotnet artifacts and copies build output into './public/qr' npm run integrate # builds react app npm run build # launches npm run start ``` ```bash npm install npm run build:all:debug npm run start ``` -------------------------------- ### PowerShell example: obtain 10.0 Blazor Web App sample Source: https://github.com/dotnet/blazor-samples/blob/main/README.md PowerShell commands to clone the repository and sparse-checkout the 10.0/BlazorSample_BlazorWebApp sample into the user's documents folder. Uses the ~/documents path for the change directory command. ```powershell cd "~/documents" git clone --depth 1 --filter=blob:none https://github.com/dotnet/blazor-samples.git --sparse cd blazor-samples git sparse-checkout init --cone git sparse-checkout set 10.0/BlazorSample_BlazorWebApp ``` -------------------------------- ### Restore wasm-tools workload Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/DotNetOnWebWorkersReact/README.md Restores the wasm-tools workload for the dotnet project. Run from the `dotnet` directory as part of the setup. ```bash cd dotnet dotnet workload restore ``` -------------------------------- ### Startup commands for Linux Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/DotNetOnWebWorkersBlazorWebAssembly/README.md Run these commands in a Linux environment to clean build and run the sample. ```bash ./run.sh cleanbuild ./run.sh run ``` -------------------------------- ### Startup commands for Windows Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/DotNetOnWebWorkersBlazorWebAssembly/README.md Run these commands in a Windows environment to clean build and run the sample. ```bash ./run.cmd cleanbuild ./run.cmd run ``` -------------------------------- ### Clone and sparse-checkout a sample folder Source: https://github.com/dotnet/blazor-samples/blob/main/README.md Use these commands to clone the blazor-samples repository with a sparse checkout and set the path to a specific sample folder. Replace the {VERSION FOLDER} and {SAMPLE FOLDER} placeholders with the appropriate values. This approach fetches only the last commit and the specified sample folder. ```cli git clone --depth 1 --filter=blob:none https://github.com/dotnet/blazor-samples.git --sparse cd blazor-samples git sparse-checkout init --cone git sparse-checkout set {VERSION FOLDER}/{SAMPLE FOLDER} ``` -------------------------------- ### Run the app with the HTTPS launch profile Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/BlazorWebAppCallWebApi/README.md Use this command to run the apps securely with the HTTPS protocol. The first launch profile in the launch settings file is used by default, which is the insecure 'http' profile. Passing the '-lp https' option overrides this to use the 'https' profile. ```bash dotnet run -lp https ``` -------------------------------- ### Load MauiAsset with FileSystem.OpenAppPackageFileAsync Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/MauiBlazorWebIdentity/MauiBlazorWeb/Resources/Raw/AboutAssets.txt Use this C# method to read a raw asset file from the app package. It opens the file as a stream and reads its contents into a string. ```csharp async Task LoadMauiAsset() { using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); using var reader = new StreamReader(stream); var contents = reader.ReadToEnd(); } ``` -------------------------------- ### MauiAsset Build Action in .csproj Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/MauiBlazorWebIdentity/MauiBlazorWeb/Resources/Raw/AboutAssets.txt Add this XML to your .csproj file to include all files in Resources\Raw as MauiAsset items. The LogicalName preserves the directory structure and file name. ```xml ``` -------------------------------- ### appsettings.json configuration for Backend and BlazorApp Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/BlazorWebAppCallWebApi/README.md These JSON files contain the endpoints for the Backend and BlazorApp apps. The BackendUrl and FrontendUrl values can be updated to new endpoints. The default URLs are https://localhost:7212 for the Backend and https://localhost:7172 for the BlazorApp, with fallbacks to https://localhost:5001 and https://localhost:5002 respectively. ```json { "BackendUrl": "https://localhost:7212" } ``` ```json { "FrontendUrl": "https://localhost:7172" } ``` -------------------------------- ### Communication flow diagram Source: https://github.com/dotnet/blazor-samples/blob/main/10.0/DotNetOnWebWorkersReact/README.md ASCII diagram showing the communication flow between the React app (main thread) and the WASM app (Web Worker). The React app calls `generate()` via client.js, the Web Worker handles QR generation, and the resulting image is transferred back via messages. ```text +-----------------------------------------------+ +---------------------+ | React App | | WASM App | | (Main Thread) | | (WebWorker Thread) | |+-----------------+ +----------------+| | +------------------+| || QrImage | | client.js || | | C#'s exports || || Component | | || Message | | (QR Generation) || || | client | || Passing | | || ||+--------------+ | API | +-------------+|| -----------> | +------------------+| ||| Button | | Call | | generate() ||| | | ||| onClick | | -------> | | function ||| Message | ^ Built-in | | ||+--------------+ | | | ||| Passing | | interop V | ||+--------------+ | | | ||| Transferable | | ||| | | update | | ||| <----------- | +------------------+| ||| | | <------- | | ||| IMAGE | | JS's imports || ||| | | | | ||| | | || ||+--------------+ | | +-------------+|| | +------------------+| |+-----------------+ +----------------+| | +------------------+| +-----------------------------------------------+ +---------------------+ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.