Skip to content
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

[browser] Add test for OutputType=Library #110620

Closed
maraf opened this issue Dec 11, 2024 · 3 comments · Fixed by #110731
Closed

[browser] Add test for OutputType=Library #110620

maraf opened this issue Dec 11, 2024 · 3 comments · Fixed by #110731
Assignees
Labels
arch-wasm WebAssembly architecture area-Infrastructure-mono in-pr There is an active PR which will close this issue when it is merged os-browser Browser variant of arch-wasm
Milestone

Comments

@maraf
Copy link
Member

maraf commented Dec 11, 2024

OutputType=Library has same publish/deployment story as OutputType=Exe.
It will create AppBundle with all necessary JS files.
User has to call dotnet.create() from dotnet.js before getAssemblyExports() is available.
The only difference is that this mode doesn't require Main() method and runMain should fail.

We should cover scenarios from #102806 with automated tests
Also discussed in #109866 (comment)
Check if wasi has enough test coverage

Possible use-cases with browser build (described in #102806 for WASI)

1. "I want to create a plain old .NET library"

  • Nothing WASM specific needed
  • Output is managed dll
  • Can be distributed as nuget package)
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
  </PropertyGroup>
</Project>

2. "I want to create a .NET library with access to browser specific APIs"

  • Use standard .NET SDK
  • Set RuntimeIdentifier to browser-wasm
  • Output is managed dll
  • Can be distributed as nuget package)
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
  </PropertyGroup>
</Project>

3. "I want to create a .NET application running in browser and have a meaningful main method" (like Blazor does)

  • Use Microsoft.NET.Sdk.WebAssembly (or Microsoft.NET.Sdk.BlazorWebAssembly) SDK
  • RuntimeIdentifier implicitly set to browser-wasm
  • Output is app bundle (dotnet.js, .NET runtime, managed dlls)
  • Can be deployed to server
<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
</Project>

4. "I want to create a .NET application running in browser, but my use-case doesn't have a meaningful main method" (I don't have a single entrypoint into my .NET code, but rather want to call JSExports from JavaScript)

  • Use Microsoft.NET.Sdk.WebAssembly SDK
  • RuntimeIdentifier implicitly set to browser-wasm
  • Output is app bundle (dotnet.js, .NET runtime, managed dlls)
  • Can be deployed to server, can be wrapped as NPM package
<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
  <PropertyGroup>
    <OutputType>Library</OutputType>
  </PropertyGroup>
</Project>

5. In use-case 4. a situation can occur when two such applications should be hosted on a single page

  • a) Each app is built separately and loaded separately (loading 2 .NET runtimes, 2 set of framework dlls trimmed to each needs)
  • b) Unifying project is created, the two app projects are referenced and a single app bundle is created and deployed

A.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
  </PropertyGroup>
</Project>

B.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
  </PropertyGroup>
</Project>

App.csproj

<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
  <PropertyGroup>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="A.csproj" />
    <ProjectReference Include="B.csproj" />
  </ItemGroup>
</Project>
@maraf maraf added arch-wasm WebAssembly architecture area-Infrastructure-mono os-browser Browser variant of arch-wasm labels Dec 11, 2024
@maraf maraf added this to the 10.0.0 milestone Dec 11, 2024
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @akoeplinger, @matouskozak
See info in area-owners.md if you want to be subscribed.

@pavelsavara pavelsavara modified the milestones: 10.0.0, Future Dec 12, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Dec 17, 2024
@pavelsavara
Copy link
Member

My new understanding is that OutputType=Library has same publish/deployment story as OutputType=Exe. It will contain AppBundle with all necessary JS files. The only difference is that it doesn't require Main() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-Infrastructure-mono in-pr There is an active PR which will close this issue when it is merged os-browser Browser variant of arch-wasm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants