Skip to content

Commit 96645ab

Browse files
committed
work
1 parent 53924ae commit 96645ab

File tree

2 files changed

+25
-88
lines changed

2 files changed

+25
-88
lines changed

aspnetcore/host-and-deploy/visual-studio-publish-profiles.md

Lines changed: 22 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ uid: host-and-deploy/visual-studio-publish-profiles
1414

1515
By [Sayed Ibrahim Hashimi](https://github.com/sayedihashimi) and [Rick Anderson](https://twitter.com/RickAndMSFT)
1616

17-
This document focuses on using Visual Studio 2019 or later to create and use [publish profiles](/visualstudio/deployment/publish-overview). The publish profiles created with Visual Studio can be used with MSBuild and Visual Studio. For instructions on publishing to Azure, see <xref:tutorials/publish-to-azure-webapp-using-vs>.
17+
This document focuses on using Visual Studio 2022 or later to create and use [publish profiles](/visualstudio/deployment/publish-overview). The publish profiles created with Visual Studio can be used with MSBuild and Visual Studio. For instructions on publishing to Azure, see <xref:tutorials/publish-to-azure-webapp-using-vs>.
18+
19+
See [Overview of Visual Studio Publish](/visualstudio/deployment/publish-overview), which contains the most current information on publishing with Visual Studio.
1820

1921
The `dotnet new mvc` command produces a project file containing the following root-level [\<Project> element](/visualstudio/msbuild/project-element-msbuild):
2022

@@ -64,6 +66,10 @@ When selecting the **Publish** button in Visual Studio or when publishing from t
6466

6567
When an ASP.NET Core project references `Microsoft.NET.Sdk.Web` in the project file, an `app_offline.htm` file is placed at the root of the web app directory. When the file is present, the ASP.NET Core Module gracefully shuts down the app and serves the `app_offline.htm` file during the deployment. For more information, see the [ASP.NET Core Module configuration reference](xref:host-and-deploy/aspnet-core-module#app_offlinehtm).
6668

69+
<!--When selecting the **Publish** button in Visual Studio, a publish profile to the project's *Properties/PublishProfiles* folder with markup similar to the following:
70+
71+
[!code-xml[](visual-studio-publish-profiles/samples/Web1.pubxml)]
72+
-->
6773
## Basic command-line publishing
6874

6975
Command-line publishing works on all .NET Core-supported platforms and doesn't require Visual Studio. In the following examples, the .NET CLI's [dotnet publish](/dotnet/core/tools/dotnet-publish) command is run from the project directory (which contains the `.csproj` file). If the project folder isn't the current working directory, explicitly pass in the project file path. For example:
@@ -92,7 +98,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
9298
Web1 -> C:\Webs\Web1\bin\Debug\{TARGET FRAMEWORK MONIKER}\publish\
9399
```
94100

95-
The default publish folder format is *bin\Debug\\{TARGET FRAMEWORK MONIKER}\publish\\*. For example, *bin\Debug\netcoreapp2.2\publish\\*.
101+
The default publish folder format is `bin\Debug\{TARGET FRAMEWORK MONIKER}`. For example, `bin\Release\net9.0\`
96102

97103
The following command specifies a `Release` build and the publishing directory:
98104

@@ -119,7 +125,7 @@ See the [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/
119125

120126
## Publish profiles
121127

122-
This section uses Visual Studio 2019 or later to create a publishing profile. Once the profile is created, publishing from Visual Studio or the command line is available. Publish profiles can simplify the publishing process, and any number of profiles can exist.
128+
This section uses Visual Studio 2022 or later to create a publishing profile. Once the profile is created, publishing from Visual Studio or the command line is available. Publish profiles can simplify the publishing process, and any number of profiles can exist.
123129

124130
Create a publish profile in Visual Studio by choosing one of the following paths:
125131

@@ -141,72 +147,30 @@ When the **Folder** publish target is selected, specify a folder path to store t
141147

142148
Once a publish profile is created, the **Publish** tab's content changes. The newly created profile appears in a drop-down list. Below the drop-down list, select **Create new profile** to create another new profile.
143149

144-
Visual Studio's publish tool produces a *Properties/PublishProfiles/{PROFILE NAME}.pubxml* MSBuild file describing the publish profile. The *.pubxml* file:
150+
Visual Studio's publish tool produces a `Properties/PublishProfiles/{PROFILE NAME}.pubxml` MSBuild file describing the publish profile. The *.pubxml* file:
145151

146152
* Contains publish configuration settings and is consumed by the publishing process.
147153
* Can be modified to customize the build and publish process.
148154

149-
When publishing to an Azure target, the *.pubxml* file contains your Azure subscription identifier. With that target type, adding this file to source control is discouraged. When publishing to a non-Azure target, it's safe to check in the *.pubxml* file.
155+
When publishing to an Azure target, the *.pubxml* file contains the Azure subscription identifier. With that target type, adding this file to source control is discouraged. When publishing to a non-Azure target, it's safe to check in the *.pubxml* file.
150156

151-
Sensitive information (like the publish password) is encrypted on a per user/machine level. It's stored in the *Properties/PublishProfiles/{PROFILE NAME}.pubxml.user* file. Because this file can store sensitive information, it shouldn't be checked into source control.
157+
Sensitive information, for example, the publish password, is encrypted on a per user/machine level. The `Properties/PublishProfiles/{PROFILE NAME}.pubxml.user` file contains the information needed by MSBuild to retrieve the password.
152158

153159
For an overview of how to publish an ASP.NET Core web app, see <xref:host-and-deploy/index>. The MSBuild tasks and targets necessary to publish an ASP.NET Core web app are open-source in the [dotnet/websdk repository](https://github.com/dotnet/sdk/tree/main/src/WebSdk).
154160

155-
The following commands can use folder, MSDeploy, and [Kudu](https://github.com/projectkudu/kudu/wiki) publish profiles. Because MSDeploy lacks cross-platform support, the following MSDeploy options are supported only on Windows.
156-
157-
**Folder (works cross-platform):**
158-
159-
```dotnetcli
160-
dotnet publish WebApplication.csproj /p:PublishProfile=<FolderProfileName>
161-
```
162-
163-
```dotnetcli
164-
dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<FolderProfileName>
165-
```
166-
167-
**MSDeploy:**
161+
<!-- Move to https://github.com/dotnet/sdk/tree/main/src/WebSdk -->
162+
`dotnet publish` and `dotnet build`:
168163

169-
```dotnetcli
170-
dotnet publish WebApplication.csproj /p:PublishProfile=<MsDeployProfileName> /p:Password=<DeploymentPassword>
171-
```
164+
* Can use folder, MSDeploy, and [Kudu](https://github.com/projectkudu/kudu/wiki) publish profiles. Because MSDeploy lacks cross-platform support, MSDeploy options are supported only on Windows.
165+
* Support Kudu APIs to publish to Azure from any platform. Visual Studio publish supports the Kudu APIs, but it's supported by WebSDK for cross-platform publish to Azure.
172166

173-
```dotnetcli
174-
dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<MsDeployProfileName> /p:Password=<DeploymentPassword>
175-
```
176-
177-
**MSDeploy package:**
178-
179-
```dotnetcli
180-
dotnet publish WebApplication.csproj /p:PublishProfile=<MsDeployPackageProfileName>
181-
```
182-
183-
```dotnetcli
184-
dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<MsDeployPackageProfileName>
185-
```
186-
187-
In the preceding examples:
188-
189-
* `dotnet publish` and `dotnet build` support Kudu APIs to publish to Azure from any platform. Visual Studio publish supports the Kudu APIs, but it's supported by WebSDK for cross-platform publish to Azure.
190-
* Don't pass `DeployOnBuild` to the `dotnet publish` command.
167+
Don't pass `DeployOnBuild` to the `dotnet publish` command.
191168

192169
For more information, see [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish).
193170

194-
Add a publish profile to the project's *Properties/PublishProfiles* folder with the following content:
195-
196-
```xml
197-
<Project>
198-
<PropertyGroup>
199-
<PublishProtocol>Kudu</PublishProtocol>
200-
<PublishSiteName>nodewebapp</PublishSiteName>
201-
<UserName>username</UserName>
202-
<Password>password</Password>
203-
</PropertyGroup>
204-
</Project>
205-
```
206-
207171
## Folder publish example
208172

209-
When publishing with a profile named *FolderProfile*, use any of the following commands:
173+
When publishing with a profile named `FolderProfile`, use any of the following commands:
210174

211175
```dotnetcli
212176
dotnet publish /p:Configuration=Release /p:PublishProfile=FolderProfile
@@ -227,33 +191,11 @@ The .NET CLI's [dotnet build](/dotnet/core/tools/dotnet-build) command calls `ms
227191

228192
The following folder publish profile was created with Visual Studio and publishes to a network share:
229193

230-
```xml
231-
<?xml version="1.0" encoding="utf-8"?>
232-
<!--
233-
This file is used by the publish/package process of your Web project.
234-
You can customize the behavior of this process by editing this
235-
MSBuild file.
236-
-->
237-
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
238-
<PropertyGroup>
239-
<WebPublishMethod>FileSystem</WebPublishMethod>
240-
<PublishProvider>FileSystem</PublishProvider>
241-
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
242-
<LastUsedPlatform>Any CPU</LastUsedPlatform>
243-
<SiteUrlToLaunchAfterPublish />
244-
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
245-
<ExcludeApp_Data>False</ExcludeApp_Data>
246-
<PublishFramework>netcoreapp1.1</PublishFramework>
247-
<ProjectGuid>c30c453c-312e-40c4-aec9-394a145dee0b</ProjectGuid>
248-
<publishUrl>\\r8\Release\AdminWeb</publishUrl>
249-
<DeleteExistingFiles>False</DeleteExistingFiles>
250-
</PropertyGroup>
251-
</Project>
252-
```
194+
[!code-xml[](visual-studio-publish-profiles/samples/FolderProfile.pubxml)]
253195

254196
In the preceding example:
255197

256-
* The `<ExcludeApp_Data>` property is present merely to satisfy an XML schema requirement. The `<ExcludeApp_Data>` property has no effect on the publish process, even if there's an *App_Data* folder in the project root. The *App_Data* folder doesn't receive special treatment as it does in ASP.NET 4.x projects.
198+
* The `<ExcludeApp_Data>` property is present to satisfy an XML schema requirement. The `<ExcludeApp_Data>` property has no effect on the publish process, even if there's an *App_Data* folder in the project root. The *App_Data* folder doesn't receive special treatment as it does in ASP.NET 4.x projects.
257199
* The `<LastUsedBuildConfiguration>` property is set to `Release`. When publishing from Visual Studio, the value of `<LastUsedBuildConfiguration>` is set using the value when the publish process is started. `<LastUsedBuildConfiguration>` is special and shouldn't be overridden in an imported MSBuild file. This property can, however, be overridden from the command line using one of the following approaches.
258200
* Using the .NET CLI:
259201

@@ -275,7 +217,7 @@ In the preceding example:
275217
276218
The following example uses an ASP.NET Core web app created by Visual Studio named *AzureWebApp*. An Azure Apps publish profile is added with Visual Studio. For more information on how to create a profile, see the [Publish profiles](#publish-profiles) section.
277219
278-
To deploy the app using a publish profile, execute the `msbuild` command from a Visual Studio **Developer Command Prompt**. The command prompt is available in the *Visual Studio* folder of the **Start** menu on the Windows taskbar. For easier access, you can add the command prompt to the **Tools** menu in Visual Studio. For more information, see [Developer Command Prompt for Visual Studio](/dotnet/framework/tools/developer-command-prompt-for-vs#run-the-command-prompt-from-inside-visual-studio).
220+
To deploy the app using a publish profile, execute the `msbuild` command from a Visual Studio **Developer Command Prompt**. The command prompt is available in the *Visual Studio* folder of the **Start** menu on the Windows taskbar. For easier access, add the command prompt to the **Tools** menu in Visual Studio. For more information, see [Developer Command Prompt for Visual Studio](/dotnet/framework/tools/developer-command-prompt-for-vs#run-the-command-prompt-from-inside-visual-studio).
279221
280222
MSBuild uses the following command syntax:
281223
@@ -464,14 +406,7 @@ For more deployment samples, see the [Web SDK README file](https://github.com/do
464406

465407
The built-in `BeforePublish` and `AfterPublish` targets execute a target before or after the publish target. Add the following elements to the publish profile to log console messages both before and after publishing:
466408

467-
```xml
468-
<Target Name="CustomActionsBeforePublish" BeforeTargets="BeforePublish">
469-
<Message Text="Inside BeforePublish" Importance="high" />
470-
</Target>
471-
<Target Name="CustomActionsAfterPublish" AfterTargets="AfterPublish">
472-
<Message Text="Inside AfterPublish" Importance="high" />
473-
</Target>
474-
```
409+
[!code-xml[](visual-studio-publish-profiles/samples/TP_before.pubxml?highlight=30-35)]
475410

476411
## Publish to a server using an untrusted certificate
477412

aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/Web1.pubxml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
1111
<ExcludeApp_Data>False</ExcludeApp_Data>
1212
<PublishFramework />
13-
<ProjectGuid>afa9f185-7ce0-4935-9da1-ab676229d68a</ProjectGuid>
13+
<ProjectGuid>
14+
<GUID Here=""></GUID>
15+
</ProjectGuid>
1416
<publishUrl>bin\Release\PublishOutput</publishUrl>
1517
<DeleteExistingFiles>False</DeleteExistingFiles>
1618
</PropertyGroup>

0 commit comments

Comments
 (0)