-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[wasm] Initial templates implementation #63683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
73e806e
820d556
44260aa
421c8d5
24f9738
0473dd8
2d8ac49
7afa008
cae1bfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <PackageType>Template</PackageType> | ||
| <PackageId>Microsoft.NET.Runtime.WebAssembly.Templates</PackageId> | ||
| <Title>WebAssembly Templates</Title> | ||
| <Authors>Microsoft</Authors> | ||
| <Description>Templates to create WebAssembly projects.</Description> | ||
| <PackageTags>dotnet-new;templates</PackageTags> | ||
|
|
||
| <TargetFramework>net6.0</TargetFramework> | ||
|
|
||
| <IncludeContentInPack>true</IncludeContentInPack> | ||
| <IncludeBuildOutput>false</IncludeBuildOutput> | ||
| <ContentTargetFolders>content</ContentTargetFolders> | ||
| <NoWarn>$(NoWarn);NU5128</NoWarn> | ||
| <IsPackable>true</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" /> | ||
| <Compile Remove="**\*" /> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="CreateManifestResourceNames" /> | ||
| <Target Name="CoreCompile" /> | ||
| <Target Name="_SetProductVersion" DependsOnTargets="GetProductVersions" BeforeTargets="Pack"> | ||
| <PropertyGroup> | ||
| <PackageVersion>$(ProductVersion)</PackageVersion> | ||
| </PropertyGroup> | ||
| </Target> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "Microsoft", | ||
| "classifications": [ "Web", "WebAssembly", "Browser" ], | ||
| "identity": "WebAssembly.Browser", | ||
| "name": "WebAssembly Browser App", | ||
| "shortName": "wasmbrowser", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "project" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| Console.WriteLine ("Hello, Console!"); | ||
|
|
||
| public class MyClass { | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still need this
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess its purpose is to avoid inlining the method during AOT. Not sure whether anything changed recently in that area though. @lewing, do you know if we need it? |
||
| public static string CallMeFromJS() | ||
| { | ||
| return "Hello, World!"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <TargetArchitecture>wasm</TargetArchitecture> | ||
| <TargetOS>Browser</TargetOS> | ||
| <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> | ||
| <UseMonoRuntime>true</UseMonoRuntime> | ||
| <WasmMainJSPath>main.js</WasmMainJSPath> | ||
| <OutputType>Exe</OutputType> | ||
| <WasmEnableES6>true</WasmEnableES6> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <WasmExtraFilesToDeploy Include="index.html" /> | ||
| <WasmExtraFilesToDeploy Include="main.js" /> | ||
| </ItemGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <!DOCTYPE html> | ||
| <!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
| <!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
| <html> | ||
|
|
||
| <head> | ||
| <title>Sample ES6</title> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <link rel="modulepreload" href="./main.js" /> | ||
| <link rel="modulepreload" href="./dotnet.js" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <span id="out"></span> | ||
| <script type='module' src="./main.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import createDotnetRuntime from './dotnet.js' | ||
|
|
||
| try { | ||
| const { MONO, BINDING, Module, RuntimeBuildInfo } = await createDotnetRuntime(); | ||
| const managedMethod = BINDING.bind_static_method("[browser] MyClass:CallMeFromJS"); | ||
| const text = managedMethod(); | ||
| document.getElementById("out").innerHTML = `${text}`; | ||
|
|
||
| await MONO.mono_run_main("browser.dll", []); | ||
| } catch (err) { | ||
| console.log(`WASM ERROR ${err}`); | ||
| document.getElementById("out").innerHTML = `error: ${err}`; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/template", | ||
| "author": "Microsoft", | ||
| "classifications": [ "Web", "WebAssembly", "Console" ], | ||
| "identity": "WebAssembly.Console", | ||
| "name": "WebAssembly Console App", | ||
| "shortName": "wasmconsole", | ||
| "tags": { | ||
| "language": "C#", | ||
| "type": "project" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
|
|
||
| Console.WriteLine("Hello World!"); | ||
|
|
||
| Console.WriteLine("Args:"); | ||
| for (int i = 0; i < args.Length; i++) { | ||
| Console.WriteLine($" args[{i}] = {args[i]}"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Node/CommonJS console App | ||
|
|
||
| Run the published application like: | ||
|
|
||
| node main.cjs | ||
|
|
||
| in `bin/$(Configuration)/net7.0/browser-wasm/AppBundle` directory. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <TargetArchitecture>wasm</TargetArchitecture> | ||
| <TargetOS>Browser</TargetOS> | ||
| <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> | ||
| <UseMonoRuntime>true</UseMonoRuntime> | ||
| <WasmMainJSPath>main.cjs</WasmMainJSPath> | ||
| <OutputType>Exe</OutputType> | ||
| <WasmEnableES6>false</WasmEnableES6> | ||
| </PropertyGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const createDotnetRuntime = require("./dotnet.js"); | ||
|
|
||
| async function main() { | ||
| const { MONO } = await createDotnetRuntime(); | ||
| const app_args = process.argv.slice(2); | ||
| await MONO.mono_run_main_and_exit("console.dll", app_args); | ||
| }; | ||
| main(); |
Uh oh!
There was an error while loading. Please reload this page.