Skip to content

Commit bc1e0aa

Browse files
committed
DLL file extension change updates
1 parent 7a429df commit bc1e0aa

File tree

4 files changed

+51
-105
lines changed

4 files changed

+51
-105
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ dotnet publish -c Release
4343

4444
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.
4545

46-
Publish locations:
46+
## Publish locations
4747

4848
:::moniker range=">= aspnetcore-8.0"
4949

5050
* 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.
5252

5353
:::moniker-end
5454

5555
:::moniker range="< aspnetcore-8.0"
5656

5757
* 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.
5858
* 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.
6060
* 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.
6161

6262
:::moniker-end

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ This article explains how to enable hosted Blazor WebAssembly deployments in env
1717
> [!NOTE]
1818
> 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.
1919
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+
2028
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.
2129

30+
::: moniker-end
31+
2232
A hosted Blazor WebAssembly app can customize its published files and packaging of app DLLs using the following features:
2333

2434
* [JavaScript initializers](xref:blazor/js-interop/index#javascript-initializers) that allow customizing the Blazor boot process.

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

Lines changed: 34 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -439,42 +439,22 @@ Blazor performs Intermediate Language (IL) linking on each Release build to remo
439439

440440
:::moniker-end
441441

442-
:::moniker range=">= aspnetcore-5.0"
442+
:::moniker range=">= aspnetcore-5.0 < aspnetcore-8.0"
443443

444444
## Change the file name extension of DLL files
445445

446-
*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.*
447447

448448
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.
449449

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.
462451

463-
:::moniker range=">= aspnetcore-5.0 < aspnetcore-8.0"
452+
For a more robust approach in environments that block the download and execution of DLL files, take ***either*** of the following approaches:
464453

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).
474456

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).
478458

479459
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.
480460

@@ -487,32 +467,22 @@ In the following examples:
487467

488468
To use a different file extension than `.bin`, replace `.bin` in the following commands with the desired file extension.
489469

490-
On Windows:
470+
# [Windows](#tab/windows)
491471

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).
493473

494-
:::moniker range=">= aspnetcore-10.0"
474+
Rename file extensions in the folder:
495475

496476
```powershell
497477
dir {PATH} | rename-item -NewName { $_.name -replace ".dll\b",".bin" }
498-
((Get-Content {PATH}\dotnet.boot.js -Raw) -replace '.dll"','.bin"') | Set-Content {PATH}\dotnet.boot.js
499478
```
500479

501-
:::moniker-end
502-
503-
:::moniker range="< aspnetcore-10.0"
480+
Rename file extensions in the `blazor.boot.json` file:
504481

505482
```powershell
506-
dir {PATH} | rename-item -NewName { $_.name -replace ".dll\b",".bin" }
507483
((Get-Content {PATH}\blazor.boot.json -Raw) -replace '.dll"','.bin"') | Set-Content {PATH}\blazor.boot.json
508484
```
509485

510-
:::moniker-end
511-
512-
:::moniker range=">= aspnetcore-5.0"
513-
514-
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-
516486
If service worker assets are also in use because the app is a [Progressive Web App (PWA)](xref:blazor/progressive-web-app):
517487

518488
```powershell
@@ -521,32 +491,22 @@ If service worker assets are also in use because the app is a [Progressive Web A
521491

522492
In the preceding command, the `{PATH}` placeholder is the path to the published `service-worker-assets.js` file.
523493

524-
On Linux or macOS:
494+
# [Linux / macOS](#tab/linux-macos)
525495

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).
527497

528-
:::moniker range=">= aspnetcore-10.0"
498+
Rename file extensions in the folder:
529499

530500
```console
531501
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
533502
```
534503

535-
:::moniker-end
536-
537-
:::moniker range="< aspnetcore-10.0"
504+
Rename file extensions in the `blazor.boot.json` file:
538505

539506
```console
540-
for f in {PATH}/*; do mv "$f" "`echo $f | sed -e 's/\.dll/.bin/g'`"; done
541507
sed -i 's/\.dll"/.bin"/g' {PATH}/blazor.boot.json
542508
```
543509

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-
550510
If service worker assets are also in use because the app is a [Progressive Web App (PWA)](xref:blazor/progressive-web-app):
551511

552512
```console
@@ -555,70 +515,40 @@ sed -i 's/\.dll"/.bin"/g' {PATH}/service-worker-assets.js
555515

556516
In the preceding command, the `{PATH}` placeholder is the path to the published `service-worker-assets.js` file.
557517

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" }
576-
((Get-Content $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\dotnet.boot.js -Raw) -replace '.dll"','.bin"') | Set-Content $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\dotnet.boot.js
577-
Remove-Item $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\dotnet.boot.js.gz
578-
Remove-Item $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\dotnet.boot.js.br
579-
```
580-
581-
Recompress `dotnet.boot.js` to re-enable compression.
518+
---
582519

583-
:::moniker-end
520+
To address the compressed `blazor.boot.json` file, adopt either of the following approaches:
584521

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.*)
586524

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:
588526

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.*)
591529

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
593531

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.
595533

596534
`ChangeDLLExtensions.ps1:`:
597535

598536
```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" }
601-
((Get-Content $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\blazor.boot.json -Raw) -replace '.dll"','.bin"') | Set-Content $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\blazor.boot.json
602-
Remove-Item $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\blazor.boot.json.gz
603-
Remove-Item $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\_framework\blazor.boot.json.br
537+
param([string]$filepath)
538+
dir $filepath\wwwroot\_framework | rename-item -NewName { $_.name -replace ".dll\b",".bin" }
539+
((Get-Content $filepath\wwwroot\_framework\blazor.boot.json -Raw) -replace '.dll"','.bin"') | Set-Content $filepath\wwwroot\_framework\blazor.boot.json
540+
Remove-Item $filepath\wwwroot\_framework\blazor.boot.json.gz
541+
Remove-Item $filepath\wwwroot\_framework\blazor.boot.json.br
604542
```
605543

606-
Recompress `blazor.boot.json` to re-enable compression.
607-
608-
:::moniker-end
609-
610-
:::moniker range=">= aspnetcore-5.0"
611-
612544
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:
613545

614546
```powershell
615-
((Get-Content $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\service-worker-assets.js -Raw) -replace '.dll"','.bin"') | Set-Content $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\service-worker-assets.js
616-
Remove-Item $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\service-worker-assets.js.gz
617-
Remove-Item $filepath\bin\Release\$tfm\browser-wasm\publish\wwwroot\service-worker-assets.js.br
547+
((Get-Content $filepath\wwwroot\service-worker-assets.js -Raw) -replace '.dll"','.bin"') | Set-Content $filepath\wwwroot\service-worker-assets.js
548+
Remove-Item $filepath\wwwroot\service-worker-assets.js.gz
549+
Remove-Item $filepath\wwwroot\service-worker-assets.js.br
618550
```
619551

620-
Recompress `service-worker-assets.js` to re-enable compression.
621-
622552
In the project file, the script is executed after publishing the app for the `Release` configuration:
623553

624554
```xml
@@ -627,6 +557,8 @@ In the project file, the script is executed after publishing the app for the `Re
627557
</Target>
628558
```
629559

560+
After publishing the app, manually recompress `blazor.boot.json`, and `service-worker-assets.js` if used, to re-enable compression.
561+
630562
> [!NOTE]
631563
> When renaming and lazy loading the same assemblies, see the guidance in <xref:blazor/webassembly-lazy-load-assemblies#onnavigateasync-events-and-renamed-assembly-files>.
632564

aspnetcore/blazor/webassembly-lazy-load-assemblies.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ The <xref:Microsoft.AspNetCore.Components.Routing.NavigationContext> object pass
351351

352352
For more information, see <xref:blazor/fundamentals/routing#handle-cancellations-in-onnavigateasync>.
353353

354+
:::moniker range=">= aspnetcore-5.0 < aspnetcore-8.0"
355+
354356
## `OnNavigateAsync` events and renamed assembly files
355357

356358
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:
360362
* Check to see if the app is running in the `Production` environment when determining which assembly names to use.
361363
* 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.
362364

365+
:::moniker-end
366+
363367
:::moniker range="< aspnetcore-8.0"
364368

365369
## Lazy load assemblies in a hosted Blazor WebAssembly solution

0 commit comments

Comments
 (0)