Skip to content

Commit 7b009e5

Browse files
authored
Improve publishing guidance (#35720)
1 parent db376e6 commit 7b009e5

File tree

1 file changed

+26
-4
lines changed
  • aspnetcore/blazor/host-and-deploy

1 file changed

+26
-4
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ Apps are published for deployment in Release configuration.
2828
# [Visual Studio](#tab/visual-studio)
2929

3030
1. Select the **Publish {APPLICATION}** command from the **Build** menu, where the `{APPLICATION}` placeholder the app's name.
31-
1. Select the *publish target*. To publish locally, select **Folder**.
32-
1. Accept the default location in the **Choose a folder** field or specify a different location. Select the **`Publish`** button.
31+
1. Select the *publish target*. To publish locally, select **Folder**. Select **Next**.
32+
1. When publishing locally, accept the default folder location or specify a different location. Select **Finish** to save the profile. Select **Close**.
33+
1. To clean the target's publish folder prior to publishing the app, select **Show all settings**. Select **Settings** > **File Publish Options** > **Delete all existing files prior to publish**. Select **Save**.
34+
1. Select the **Publish** button.
3335

34-
# [.NET CLI](#tab/net-cli)
36+
# [Visual Studio Code and .NET CLI](#tab/visual-studio-code-dotnet-cli)
3537

36-
Use the [`dotnet publish`](/dotnet/core/tools/dotnet-publish) command to publish the app with a Release configuration:
38+
Open a command shell to the project's root directory.
39+
40+
Use the [`dotnet publish`](/dotnet/core/tools/dotnet-publish) command to publish the app:
41+
42+
```dotnetcli
43+
dotnet publish
44+
```
45+
46+
Prior to .NET 8, the default publish configuration is `Debug`. When publishing an app that targets .NET 7 or earlier, pass the `-c|--configuration` option to the command with "`Release`" to publish in `Release` configuration:
3747

3848
```dotnetcli
3949
dotnet publish -c Release
@@ -43,6 +53,18 @@ dotnet publish -c Release
4353

4454
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.
4555

56+
## Empty the target publish folder
57+
58+
When using the [`dotnet publish`](/dotnet/core/tools/dotnet-publish) command in a command shell to publish an app, the command generates the necessary files for deployment based on the current state of the project and places the files into the specified output folder. The command doesn't automatically clean the target folder before publishing the app.
59+
60+
To empty the target folder automatically before the app is published, add the following MSBuild target to the app's project file (`.csproj`) under the root `<Project>` element:
61+
62+
```xml
63+
<Target Name="_RemovePublishDirBeforePublishing" BeforeTargets="BeforePublish">
64+
<RemoveDir Directories="$(PublishDir)" Condition="'$(PublishDir)' != ''" />
65+
</Target>
66+
```
67+
4668
## Default publish locations
4769

4870
:::moniker range=">= aspnetcore-8.0"

0 commit comments

Comments
 (0)