Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,30 @@ public void TypeScriptDefinitionsCopiedToWwwrootOnBuild(Configuration config, bo
Assert.False(fileExists, $"dotnet.d.ts should not exist at {dotnetDtsWwwrootPath} after the build with WasmEmitTypeScriptDefinitions={shouldEmit}");
}
}

[Theory]
[InlineData("true", true)]
[InlineData("false", false)]
[InlineData("", true)] // Default case
public void UseMonoRuntimeParameter(string useMonoRuntimeArg, bool expectUseMonoRuntime)
{
Configuration config = Configuration.Debug;
string extraArgs = string.IsNullOrEmpty(useMonoRuntimeArg) ? "" : $"--UseMonoRuntime {useMonoRuntimeArg}";
ProjectInfo info = CreateWasmTemplateProject(Template.WasmBrowser, config, aot: false, "usemonoruntime", extraArgs: extraArgs);

string projectDirectory = Path.GetDirectoryName(info.ProjectFilePath)!;
string projectFile = File.ReadAllText(info.ProjectFilePath);

// Verify UseMonoRuntime presence in the project file
bool containsUseMonoRuntime = projectFile.Contains("<UseMonoRuntime>true</UseMonoRuntime>");
if (expectUseMonoRuntime)
{
Assert.True(containsUseMonoRuntime, $"Expected <UseMonoRuntime>true</UseMonoRuntime> to be present in the project file when --UseMonoRuntime {useMonoRuntimeArg}");
}
else
{
Assert.False(containsUseMonoRuntime, $"Expected <UseMonoRuntime>true</UseMonoRuntime> to not be present in the project file when --UseMonoRuntime {useMonoRuntimeArg}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
"defaultValue": "net11.0",
"replaces": "netX.0",
"displayName": "framework"
},
"UseMonoRuntime": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "true",
"description": "Whether to use the Mono runtime for WebAssembly.",
"displayName": "Use Mono Runtime"
}
}
}
62 changes: 62 additions & 0 deletions src/mono/wasm/templates/templates/browser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# WebAssembly Browser App Template

This template creates a .NET app that runs on WebAssembly in a browser.

## Template Options

### UseMonoRuntime

**Parameter:** `--UseMonoRuntime`
**Type:** boolean
**Default:** `true`

Determines whether to use the Mono runtime for WebAssembly.

When set to `true`, the generated project file will include:
```xml
<UseMonoRuntime>true</UseMonoRuntime>
```

#### Usage Examples

Create a project with Mono runtime (default):
```bash
dotnet new wasmbrowser -n MyApp
```

Or explicitly specify:
```bash
dotnet new wasmbrowser -n MyApp --UseMonoRuntime true
```

Create a project without the Mono runtime property:
```bash
dotnet new wasmbrowser -n MyApp --UseMonoRuntime false
```

## Getting Started

After creating your project:

1. Navigate to your project directory:
```bash
cd MyApp
```

2. Run the application:
```bash
dotnet run
```

3. Open your browser to the URL displayed in the console output (typically `https://localhost:7000` or `http://localhost:5000`).

## Project Structure

- **Program.cs** - The entry point of your application
- **wwwroot/** - Static web assets (HTML, CSS, JavaScript)
- **Properties/** - Project properties and configuration

## Learn More

- [.NET WebAssembly Documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/webassembly)
- [Mono Runtime](https://www.mono-project.com/)
3 changes: 3 additions & 0 deletions src/mono/wasm/templates/templates/browser/browser.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<TargetFramework>netX.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OverrideHtmlAssetPlaceholders>true</OverrideHtmlAssetPlaceholders>
<!--#if (UseMonoRuntime) -->
<UseMonoRuntime>true</UseMonoRuntime>
<!--#endif -->
</PropertyGroup>

<ItemGroup>
Expand Down
Loading