You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/host-and-deploy/index.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,20 +43,20 @@ dotnet publish -c Release
43
43
44
44
Publishing the app triggers a [restore](/dotnet/core/tools/dotnet-restore) of the project's dependencies and [builds](/dotnet/core/tools/dotnet-build) the project before creating the assets for deployment. As part of the build process, unused methods and assemblies are removed to reduce app download size and load times.
45
45
46
-
Publish locations:
46
+
## Publish locations
47
47
48
48
:::moniker range=">= aspnetcore-8.0"
49
49
50
50
* Blazor Web App: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish` folder, where the `{TARGET FRAMEWORK}` placeholder is the target framework. Deploy the contents of the `publish` folder to the host.
51
-
* Standalone Blazor WebAssembly: The app is published into the `bin\Release\{TARGET FRAMEWORK}\browser-wasm\publish\` folder. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
51
+
* Standalone Blazor WebAssembly: The app is published into the `bin/Release/{TARGET FRAMEWORK}/publish` folder. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
52
52
53
53
:::moniker-end
54
54
55
55
:::moniker range="< aspnetcore-8.0"
56
56
57
57
* Blazor Server: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish` folder, where the `{TARGET FRAMEWORK}` placeholder is the target framework.. Deploy the contents of the `publish` folder to the host.
58
58
* Blazor WebAssembly
59
-
* Standalone: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` or `bin\Release\{TARGET FRAMEWORK}\browser-wasm\publish` folder, depending on the version of the SDK used to publish the app. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
59
+
* Standalone: The app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` or `bin/Release/{TARGET FRAMEWORK}/browser-wasm/publish` folder, depending on the version of the SDK used to publish the app. To deploy the app as a static site, copy the contents of the `wwwroot` folder to the static site host.
60
60
* Hosted: The client Blazor WebAssembly app is published into the `/bin/Release/{TARGET FRAMEWORK}/publish/wwwroot` folder of the server app, along with any other static web assets of the client app. Deploy the contents of the `publish` folder to the host.
Copy file name to clipboardExpand all lines: aspnetcore/blazor/host-and-deploy/webassembly/deployment-layout.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,18 @@ This article explains how to enable hosted Blazor WebAssembly deployments in env
17
17
> [!NOTE]
18
18
> This guidance addresses environments that block clients from downloading and executing DLLs. In .NET 8 or later, Blazor uses the Webcil file format to address this problem. For more information, see <xref:blazor/host-and-deploy/webassembly/index?view=aspnetcore-8.0&preserve-view=true#webcil-packaging-format-for-net-assemblies>. Multipart bundling using the experimental NuGet package described by this article isn't supported for Blazor apps in .NET 8 or later. You can use the guidance in this article to create your own multipart bundling NuGet package for .NET 8 or later.
19
19
20
+
:::moniker range=">= aspnetcore-8.0"
21
+
22
+
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. 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.
23
+
24
+
::: moniker-end
25
+
26
+
:::moniker range="< aspnetcore-8.0"
27
+
20
28
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/index#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.
21
29
30
+
::: moniker-end
31
+
22
32
A hosted Blazor WebAssembly app can customize its published files and packaging of app DLLs using the following features:
23
33
24
34
*[JavaScript initializers](xref:blazor/js-interop/index#javascript-initializers) that allow customizing the Blazor boot process.
*This section applies to ASP.NET Core 6.x and 7.x. In ASP.NET Core in .NET 8 or later, .NET assemblies are deployed as WebAssembly files (`.wasm`) using the Webcil file format. In ASP.NET Core in .NET 8 or later, this section only applies if the Webcil file format has been disabled in the app's project file.*
446
+
*This section applies to .NET 5 through .NET 7. In .NET 8, .NET assemblies are deployed as WebAssembly files (`.wasm`) using the Webcil file format.*
447
447
448
448
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.
449
449
450
-
:::moniker-end
451
-
452
-
:::moniker range=">= aspnetcore-8.0"
453
-
454
-
> [!NOTE]
455
-
> 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.
456
-
>
457
-
> For a more robust approach in environments that block the download and execution of DLL files, use ASP.NET Core in .NET 8 or later, which 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.
458
-
>
459
-
> Third-party approaches exist for dealing with this problem. For more information, see the resources at [Awesome Blazor](https://github.com/AdrienTorris/awesome-blazor).
460
-
461
-
:::moniker-end
450
+
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, take ***either*** of the following approaches:
464
453
465
-
> [!NOTE]
466
-
> 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.
467
-
>
468
-
> For a more robust approach in environments that block the download and execution of DLL files, take ***either*** of the following approaches:
469
-
>
470
-
> * Use ASP.NET Core in .NET 8 or later, which 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.
471
-
> * In ASP.NET Core in .NET 6 or later, use a [custom deployment layout](xref:blazor/host-and-deploy/webassembly/deployment-layout).
472
-
>
473
-
> Third-party approaches exist for dealing with this problem. For more information, see the resources at [Awesome Blazor](https://github.com/AdrienTorris/awesome-blazor).
454
+
* Use .NET 8 or later, which 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.
455
+
* In .NET 6 or later, use a [custom deployment layout](xref:blazor/host-and-deploy/webassembly/deployment-layout).
474
456
475
-
:::moniker-end
476
-
477
-
:::moniker range=">= aspnetcore-5.0"
457
+
Third-party approaches exist for dealing with this problem. For more information, see the resources at [Awesome Blazor](https://github.com/AdrienTorris/awesome-blazor).
478
458
479
459
After publishing the app, use a shell script or DevOps build pipeline to rename `.dll` files to use a different file extension in the directory of the app's published output.
480
460
@@ -487,32 +467,22 @@ In the following examples:
487
467
488
468
To use a different file extension than `.bin`, replace `.bin` in the following commands with the desired file extension.
489
469
490
-
On Windows:
470
+
# [Windows](#tab/windows)
491
471
492
-
:::moniker-end
472
+
In the following commands, the `{PATH}` placeholder is the path to the published `_framework` folder in the [`publish` folder](xref:blazor/host-and-deploy/index#publish-locations).
493
473
494
-
:::moniker range=">= aspnetcore-10.0"
474
+
Rename file extensions in the folder:
495
475
496
476
```powershell
497
477
dir {PATH} | rename-item -NewName { $_.name -replace ".dll\b",".bin" }
In the preceding command, the `{PATH}` placeholder is the path to the published `_framework` folder (for example, `.\bin\Release\{TFM}\browser-wasm\publish\wwwroot\_framework` from the project's root folder, where the `{TFM}` placeholder is the [target framework moniker (TFM)](/dotnet/standard/frameworks)).
515
-
516
486
If service worker assets are also in use because the app is a [Progressive Web App (PWA)](xref:blazor/progressive-web-app):
517
487
518
488
```powershell
@@ -521,32 +491,22 @@ If service worker assets are also in use because the app is a [Progressive Web A
521
491
522
492
In the preceding command, the `{PATH}` placeholder is the path to the published `service-worker-assets.js` file.
523
493
524
-
On Linux or macOS:
494
+
# [Linux / macOS](#tab/linux-macos)
525
495
526
-
:::moniker-end
496
+
In the following commands, the `{PATH}` placeholder is the path to the published `_framework` folder in the [`publish` folder](xref:blazor/host-and-deploy/index#publish-locations).
527
497
528
-
:::moniker range=">= aspnetcore-10.0"
498
+
Rename file extensions in the folder:
529
499
530
500
```console
531
501
for f in {PATH}/*; do mv "$f" "`echo $f | sed -e 's/\.dll/.bin/g'`"; done
532
-
sed -i 's/\.dll"/.bin"/g' {PATH}/dotnet.boot.js
533
502
```
534
503
535
-
:::moniker-end
536
-
537
-
:::moniker range="< aspnetcore-10.0"
504
+
Rename file extensions in the `blazor.boot.json` file:
538
505
539
506
```console
540
-
for f in {PATH}/*; do mv "$f" "`echo $f | sed -e 's/\.dll/.bin/g'`"; done
541
507
sed -i 's/\.dll"/.bin"/g' {PATH}/blazor.boot.json
542
508
```
543
509
544
-
:::moniker-end
545
-
546
-
:::moniker range=">= aspnetcore-5.0"
547
-
548
-
In the preceding command, the `{PATH}` placeholder is the path to the published `_framework` folder (for example, `.\bin\Release\{TFM}\browser-wasm\publish\wwwroot\_framework` from the project's root folder), where the `{TFM}` placeholder is the [target framework moniker (TFM)](/dotnet/standard/frameworks))
549
-
550
510
If service worker assets are also in use because the app is a [Progressive Web App (PWA)](xref:blazor/progressive-web-app):
551
511
552
512
```console
@@ -555,70 +515,40 @@ sed -i 's/\.dll"/.bin"/g' {PATH}/service-worker-assets.js
555
515
556
516
In the preceding command, the `{PATH}` placeholder is the path to the published `service-worker-assets.js` file.
557
517
558
-
:::moniker-end
559
-
560
-
:::moniker range=">= aspnetcore-10.0"
561
-
562
-
To address the compressed `dotnet.boot.js.gz` and `dotnet.boot.js.br` files, adopt either of the following approaches:
563
-
564
-
* Remove the compressed `dotnet.boot.js.gz` and `dotnet.boot.js.br` files. **Compression is disabled with this approach.**
565
-
* Recompress the updated `dotnet.boot.js` file.
566
-
567
-
The preceding guidance for the compressed `dotnet.boot.js` file also applies when service worker assets are in use. Remove or recompress `service-worker-assets.js.br` and `service-worker-assets.js.gz`. Otherwise, file integrity checks fail in the browser.
568
-
569
-
The following Windows example for .NET 6 or later uses a PowerShell script placed at the root of the project. The following script, which disables compression, is the basis for further modification if you wish to recompress the `dotnet.boot.js` file. Pass the app's path and TFM to the script.
570
-
571
-
`ChangeDLLExtensions.ps1:`:
572
-
573
-
```powershell
574
-
param([string]$filepath,[string]$tfm)
575
-
dir $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework | rename-item -NewName { $_.name -replace ".dll\b",".bin" }
Recompress `dotnet.boot.js` to re-enable compression.
518
+
---
582
519
583
-
:::moniker-end
520
+
To address the compressed `blazor.boot.json` file, adopt either of the following approaches:
584
521
585
-
:::moniker range="< aspnetcore-10.0"
522
+
* Recompress the updated `blazor.boot.json` file, producing new `blazor.boot.json.gz` and `blazor.boot.json.br` files. (*Recommended*)
523
+
* Remove the compressed `blazor.boot.json.gz` and `blazor.boot.json.br` files. (*Compression is disabled with this approach.*)
586
524
587
-
To address the compressed `blazor.boot.json.gz` and `blazor.boot.json.br` files, adopt either of the following approaches:
525
+
For a [Progressive Web App (PWA)](xref:blazor/progressive-web-app)'s compressed `service-worker-assets.js` file, adopt either of the following approaches:
588
526
589
-
*Remove the compressed `blazor.boot.json.gz` and `blazor.boot.json.br` files. **Compression is disabled with this approach.**
590
-
*Recompress the updated`blazor.boot.json` file.
527
+
*Recompress the updated `service-worker-assets.js` file, producing new `service-worker-assets.js.br` and `service-worker-assets.js.gz` files. (*Recommended*)
528
+
*Remove the compressed`blazor.boot.json.gz` and `blazor.boot.json.br` files. (*Compression is disabled with this approach.*)
591
529
592
-
The preceding guidance for the compressed `blazor.boot.json` file also applies when service worker assets are in use. Remove or recompress `service-worker-assets.js.br` and `service-worker-assets.js.gz`. Otherwise, file integrity checks fail in the browser.
530
+
### Automate the extension change
593
531
594
-
The following Windows example for .NET 6 to .NET 9 uses a PowerShell script placed at the root of the project. The following script, which disables compression, is the basis for further modification if you wish to recompress the `blazor.boot.json` file. Pass the app's path and TFM to the script.
532
+
The following Windows example for .NET 6 or later uses a PowerShell script placed at the root of the project. The following script, which disables compression, is the basis for further modification if you wish to recompress the `blazor.boot.json` file and `service-worker-assets.js` file if the app is a [Progressive Web App (PWA)](xref:blazor/progressive-web-app). Pass the path to the [`publish` folder](xref:blazor/host-and-deploy/index#publish-locations) to the script.
595
533
596
534
`ChangeDLLExtensions.ps1:`:
597
535
598
536
```powershell
599
-
param([string]$filepath,[string]$tfm)
600
-
dir $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework | rename-item -NewName { $_.name -replace ".dll\b",".bin" }
Recompress `blazor.boot.json` to re-enable compression.
607
-
608
-
:::moniker-end
609
-
610
-
:::moniker range=">= aspnetcore-5.0"
611
-
612
544
If service worker assets are also in use because the app is a [Progressive Web App (PWA)](xref:blazor/progressive-web-app), add the following commands:
Recompress `service-worker-assets.js` to re-enable compression.
621
-
622
552
In the project file, the script is executed after publishing the app for the `Release` configuration:
623
553
624
554
```xml
@@ -627,6 +557,8 @@ In the project file, the script is executed after publishing the app for the `Re
627
557
</Target>
628
558
```
629
559
560
+
After publishing the app, manually recompress `blazor.boot.json`, and `service-worker-assets.js` if used, to re-enable compression.
561
+
630
562
> [!NOTE]
631
563
> When renaming and lazy loading the same assemblies, see the guidance in <xref:blazor/webassembly-lazy-load-assemblies#onnavigateasync-events-and-renamed-assembly-files>.
## `OnNavigateAsync` events and renamed assembly files
355
357
356
358
The resource loader relies on the assembly names that are defined in the boot manifest file. If [assemblies are renamed](xref:blazor/host-and-deploy/webassembly/index#change-the-file-name-extension-of-dll-files), the assembly names used in an <xref:Microsoft.AspNetCore.Components.Routing.Router.OnNavigateAsync> callback and the assembly names in the boot manifest file are out of sync.
@@ -360,6 +362,8 @@ To rectify this:
360
362
* Check to see if the app is running in the `Production` environment when determining which assembly names to use.
361
363
* Store the renamed assembly names in a separate file and read from that file to determine what assembly name to use with the <xref:Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader> service and <xref:Microsoft.AspNetCore.Components.Routing.Router.OnNavigateAsync> callback.
362
364
365
+
:::moniker-end
366
+
363
367
:::moniker range="< aspnetcore-8.0"
364
368
365
369
## Lazy load assemblies in a hosted Blazor WebAssembly solution
0 commit comments