Skip to content

Commit 8141927

Browse files
authored
.NET assembly packaging (Webcil) (#29542)
1 parent 75bf3a1 commit 8141927

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

aspnetcore/blazor/host-and-deploy/webassembly-deployment-layout.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,37 @@ uid: blazor/host-and-deploy/webassembly-deployment-layout
1212

1313
[!INCLUDE[](~/includes/not-latest-version.md)]
1414

15+
:::moniker range=">= aspnetcore-8.0"
16+
17+
This article explains how to customize Blazor WebAssembly deployments when the [Webcil packaging format for .NET assemblies is disabled](xref:blazor/host-and-deploy/webassembly#webcil-packaging-format-for-net-assemblies). The app's DLLs are packaged into a multipart bundle file and downloaded together.
18+
19+
:::moniker-end
20+
21+
:::moniker range="< aspnetcore-8.0"
22+
1523
This article explains how to enable Blazor WebAssembly deployments in environments that block the download and execution of dynamic-link library (DLL) files.
1624

1725
Blazor WebAssembly apps require [dynamic-link libraries (DLLs)](/windows/win32/dlls/dynamic-link-libraries) to function, but some environments block clients from downloading and executing DLLs. In a subset of these environments, [changing the file name extension of DLL files (`.dll`)](xref:blazor/host-and-deploy/webassembly#change-the-file-name-extension-of-dll-files) is sufficient to bypass security restrictions, but security products are often able to scan the content of files traversing the network and block or quarantine DLL files. This article describes one approach for enabling Blazor WebAssembly apps in these environments, where a multipart bundle file is created from the app's DLLs so that the DLLs can be downloaded together bypassing security restrictions.
1826

27+
:::moniker-end
28+
1929
A hosted Blazor WebAssembly app can customize its published files and packaging of app DLLs using the following features:
2030

2131
* [JavaScript initializers](xref:blazor/js-interop/index#javascript-initializers) that allow customizing the Blazor boot process.
2232
* MSBuild extensibility to transform the list of published files and define *Blazor Publish Extensions*. Blazor Publish Extensions are files defined during the publish process that provide an alternative representation for the set of files required to run a published Blazor WebAssembly app. In this article, a Blazor Publish Extension is created that produces a multipart bundle with all of the app's DLLs packed into a single file so that the DLLs can be downloaded together.
2333

2434
The approach demonstrated in this article serves as a starting point for developers to devise their own strategies and custom loading processes.
2535

36+
:::moniker range="< aspnetcore-8.0"
37+
2638
> [!WARNING]
2739
> Any approach taken to circumvent a security restriction must be carefully considered for its security implications. We recommend exploring the subject further with your organization's network security professionals before adopting the approach in this article. Alternatives to consider include:
2840
>
2941
> * Enable security appliances and security software to permit network clients to download and use the exact files required by a Blazor WebAssembly app.
3042
> * Switch from the Blazor WebAssembly hosting model to the [Blazor Server hosting model](xref:blazor/hosting-models#blazor-server), which maintains all of the app's C# code on the server and doesn't require downloading DLLs to clients. Blazor Server also offers the advantage of keeping C# code private without requiring the use of web API apps for C# code privacy with Blazor WebAssembly apps.
3143
44+
:::moniker-end
45+
3246
## Experimental NuGet package and sample app
3347

3448
The approach described in this article is used by the *experimental* [`Microsoft.AspNetCore.Components.WebAssembly.MultipartBundle` package (NuGet.org)](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.WebAssembly.MultipartBundle). The package contains MSBuild targets to customize the Blazor publish output and a [JavaScript initializer](xref:blazor/js-interop/index#javascript-initializers) to use a custom [boot resource loader](xref:blazor/fundamentals/startup#load-boot-resources), each of which are described in detail later in this article.

aspnetcore/blazor/host-and-deploy/webassembly.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ The following deployment strategies are supported:
2525
* The Blazor app is placed on a static hosting web server or service, where .NET isn't used to serve the Blazor app. This strategy is covered in the [Standalone deployment](#standalone-deployment) section, which includes information on hosting a Blazor WebAssembly app as an IIS sub-app.
2626
* An ASP.NET Core app hosts multiple Blazor WebAssembly apps. For more information, see <xref:blazor/host-and-deploy/multiple-hosted-webassembly>.
2727

28+
:::moniker range=">= aspnetcore-8.0"
29+
30+
## Webcil packaging format for .NET assemblies
31+
32+
[Webcil](https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md) is a web-friendly packaging format for .NET assemblies designed to enable using Blazor WebAssembly in restrictive network environments. Webcil files use a standard WebAssembly wrapper, where the assemblies are deployed as WebAssembly files that use the standard `.wasm` file extension.
33+
34+
Webcil is the default packaging format when you publish a Blazor WebAssembly app. To disable the use of Webcil, set the following MS Build property in the app's project file:
35+
36+
```xml
37+
<PropertyGroup>
38+
<WasmEnableWebcil>false</WasmEnableWebcil>
39+
</PropertyGroup>
40+
```
41+
42+
:::moniker-end
43+
2844
:::moniker range=">= aspnetcore-6.0"
2945

3046
## Ahead-of-time (AOT) compilation
@@ -492,6 +508,45 @@ To deploy a Blazor WebAssembly app to CentOS 7 or later:
492508

493509
1. Create the Apache configuration file. The following example is a simplified configuration file (`blazorapp.config`):
494510

511+
:::moniker range=">= aspnetcore-8.0"
512+
513+
```
514+
<VirtualHost *:80>
515+
ServerName www.example.com
516+
ServerAlias *.example.com
517+
518+
DocumentRoot "/var/www/blazorapp"
519+
ErrorDocument 404 /index.html
520+
521+
AddType application/wasm .wasm
522+
523+
<Directory "/var/www/blazorapp">
524+
Options -Indexes
525+
AllowOverride None
526+
</Directory>
527+
528+
<IfModule mod_deflate.c>
529+
AddOutputFilterByType DEFLATE text/css
530+
AddOutputFilterByType DEFLATE application/javascript
531+
AddOutputFilterByType DEFLATE text/html
532+
AddOutputFilterByType DEFLATE application/octet-stream
533+
AddOutputFilterByType DEFLATE application/wasm
534+
<IfModule mod_setenvif.c>
535+
BrowserMatch ^Mozilla/4 gzip-only-text/html
536+
BrowserMatch ^Mozilla/4.0[678] no-gzip
537+
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
538+
</IfModule>
539+
</IfModule>
540+
541+
ErrorLog /var/log/httpd/blazorapp-error.log
542+
CustomLog /var/log/httpd/blazorapp-access.log common
543+
</VirtualHost>
544+
```
545+
546+
:::moniker-end
547+
548+
:::moniker range="< aspnetcore-8.0"
549+
495550
```
496551
<VirtualHost *:80>
497552
ServerName www.example.com
@@ -526,6 +581,8 @@ To deploy a Blazor WebAssembly app to CentOS 7 or later:
526581
</VirtualHost>
527582
```
528583

584+
:::moniker-end
585+
529586
1. Place the Apache configuration file into the `/etc/httpd/conf.d/` directory, which is the default Apache configuration directory in CentOS 7.
530587

531588
1. Place the app's files into the `/var/www/blazorapp` directory (the location specified to `DocumentRoot` in the configuration file).
@@ -788,10 +845,17 @@ Blazor performs Intermediate Language (IL) linking on each Release build to remo
788845

789846
## Change the file name extension of DLL files
790847

848+
*This section applies to ASP.NET Core 6.x and 7.x. In ASP.NET Core 8.0 or later, .NET assemblies are deployed as WebAssembly files (`.wasm`) using the Webcil file format. In ASP.NET Core 8.0 or later, this section only applies if the Webcil file format has been disabled in the app's project file.*
849+
791850
If a firewall, anti-virus program, or network security appliance is blocking the transmission of the app's dynamic-link library (DLL) files (`.dll`), you can follow the guidance in this section to change the file name extensions of the app's published DLL files.
792851

793852
> [!NOTE]
794-
> Changing the file name extensions of the app's DLL files might not resolve the problem because many security systems scan the content of the app's files, not merely check file extensions. For a more robust approach in environments that block the download and execution of DLL files, see <xref:blazor/host-and-deploy/webassembly-deployment-layout>.
853+
> Changing the file name extensions of the app's DLL files might not resolve the problem because many security systems scan the content of the app's files, not merely check file extensions.
854+
>
855+
> For a more robust approach in environments that block the download and execution of DLL files, take ***either*** of the following approaches:
856+
>
857+
> * Use ASP.NET Core 8.0 or later, which by default packages .NET assemblies as WebAssembly files (`.wasm`) using the [Webcil](https://github.com/dotnet/runtime/blob/main/docs/design/mono/webcil.md) file format. For more information, see the *Webcil packaging format for .NET assemblies* section in an 8.0 or later version of this article.
858+
> * In ASP.NET Core 6.0 or later, use a [custom deployment layout](xref:blazor/host-and-deploy/webassembly-deployment-layout).
795859
>
796860
> Third-party approaches exist for dealing with this problem. For more information, see the resources at [Awesome Blazor](https://github.com/AdrienTorris/awesome-blazor).
797861

aspnetcore/blazor/progressive-web-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ By default, this manifest lists:
267267
* Any Blazor-managed resources, such as .NET assemblies and the .NET WebAssembly runtime files required to function offline.
268268
* All resources for publishing to the app's `wwwroot` directory, such as images, stylesheets, and JavaScript files, including static web assets supplied by external projects and NuGet packages.
269269

270-
You can control which of these resources are fetched and cached by the service worker by editing the logic in `onInstall` in `service-worker.published.js`. By default, the service worker fetches and caches files matching typical web file name extensions such as `.html`, `.css`, `.js`, and `.wasm`, plus file types specific to Blazor WebAssembly (`.dll`, `.pdb`).
270+
You can control which of these resources are fetched and cached by the service worker by editing the logic in `onInstall` in `service-worker.published.js`. By default, the service worker fetches and caches files matching typical web file name extensions such as `.html`, `.css`, `.js`, and `.wasm`, plus file types specific to Blazor WebAssembly, such as `.pdb` files (all versions) and `.dll` files (ASP.NET Core 7.0 or earlier).
271271

272272
To include additional resources that aren't present in the app's `wwwroot` directory, define extra MSBuild `ItemGroup` entries, as shown in the following example:
273273

0 commit comments

Comments
 (0)