Skip to content

Commit f0e6804

Browse files
ROPC: dotnet publish /2 (#34114)
* ROPC: dotnet publish /2 * work * work * work * work * work * work * work * work * work * work * Update aspnetcore/host-and-deploy/visual-studio-publish-profiles.md Co-authored-by: Tom Dykstra <[email protected]> * react to feedbac --------- Co-authored-by: Tom Dykstra <[email protected]>
1 parent 50a34f5 commit f0e6804

File tree

4 files changed

+97
-134
lines changed

4 files changed

+97
-134
lines changed

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

Lines changed: 41 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ 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+
For the most current and detailed information on:
20+
21+
* Publishing with Visual studio, see [Overview of Visual Studio Publish](/visualstudio/deployment/publish-overview)
22+
* MSBuild, see [MSBuild](/visualstudio/msbuild/msbuild-introduction)
23+
* Publishing with MSBuild, see [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish)
1824

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

@@ -24,7 +30,7 @@ The `dotnet new mvc` command produces a project file containing the following ro
2430
</Project>
2531
```
2632

27-
The preceding `<Project>` element's `Sdk` attribute imports the MSBuild [properties](/visualstudio/msbuild/msbuild-properties) and [targets](/visualstudio/msbuild/msbuild-targets) from *$(MSBuildSDKsPath)\Microsoft.NET.Sdk.Web\Sdk\Sdk.props* and *$(MSBuildSDKsPath)\Microsoft.NET.Sdk.Web\Sdk\Sdk.targets*, respectively. The default location for `$(MSBuildSDKsPath)` (with Visual Studio 2019 Enterprise) is the *%programfiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks* folder.
33+
The preceding `<Project>` element's `Sdk` attribute imports the MSBuild [properties](/visualstudio/msbuild/msbuild-properties) and [targets](/visualstudio/msbuild/msbuild-targets) from *$(MSBuildSDKsPath)\Microsoft.NET.Sdk.Web\Sdk\Sdk.props* and *$(MSBuildSDKsPath)\Microsoft.NET.Sdk.Web\Sdk\Sdk.targets*, respectively. The default location for `$(MSBuildSDKsPath)` (with Visual Studio 2022) is the *%programfiles%\Microsoft Visual Studio\2022\Preview\MSBuild\Sdks* folder.
2834

2935
`Microsoft.NET.Sdk.Web` ([Web SDK](xref:razor-pages/web-sdk)) depends on other SDKs, including `Microsoft.NET.Sdk` ([.NET Core SDK](/dotnet/core/project-sdk/msbuild-props)) and `Microsoft.NET.Sdk.Razor` ([Razor SDK](xref:razor-pages/sdk)). The MSBuild properties and targets associated with each dependent SDK are imported. Publish targets import the appropriate set of targets based on the publish method used.
3036

@@ -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

@@ -102,7 +108,7 @@ dotnet publish -c Release -o C:\MyWebs\test
102108

103109
The `dotnet publish` command calls MSBuild, which invokes the `Publish` target. Any parameters passed to `dotnet publish` are passed to MSBuild. The `-c` and `-o` parameters map to MSBuild's `Configuration` and `OutputPath` properties, respectively.
104110

105-
MSBuild properties can be passed using either of the following formats:
111+
[MSBuild properties](/visualstudio/msbuild/msbuild-command-line-reference) can be passed using either of the following formats:
106112

107113
* `-p:<NAME>=<VALUE>`
108114
* `/p:<NAME>=<VALUE>`
@@ -115,20 +121,21 @@ dotnet publish -c Release /p:PublishDir=//r8/release/AdminWeb
115121

116122
Confirm that the published app for deployment isn't running. Files in the *publish* folder are locked when the app is running. Deployment can't occur because locked files can't be copied.
117123

124+
See the [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish) readme file for more information.
125+
118126
## Publish profiles
119127

120-
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.
121129

122130
Create a publish profile in Visual Studio by choosing one of the following paths:
123131

124132
* Right-click the project in **Solution Explorer** and select **Publish**.
125133
* Select **Publish {PROJECT NAME}** from the **Build** menu.
126134

127-
The **Publish** tab of the app capabilities page is displayed. If the project lacks a publish profile, the **Pick a publish target** page is displayed. You're asked to select one of the following publish targets:
135+
The **Publish** tab of the app capabilities page is displayed. Several publish targets are available, including:
128136

129-
* Azure App Service
130-
* Azure App Service on Linux
131-
* Azure Virtual Machines
137+
* Azure
138+
* Docker Container Registry
132139
* Folder
133140
* IIS, FTP, Web Deploy (for any web server)
134141
* Import Profile
@@ -139,72 +146,32 @@ When the **Folder** publish target is selected, specify a folder path to store t
139146

140147
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.
141148

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

144151
* Contains publish configuration settings and is consumed by the publishing process.
145152
* Can be modified to customize the build and publish process.
146153

147-
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.
148-
149-
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.
150-
151-
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).
152-
153-
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.
154+
When publishing to an Azure target, the *.pubxml* file:
154155

155-
**Folder (works cross-platform):**
156-
157-
```dotnetcli
158-
dotnet publish WebApplication.csproj /p:PublishProfile=<FolderProfileName>
159-
```
160-
161-
```dotnetcli
162-
dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<FolderProfileName>
163-
```
156+
* Contains the Azure subscription identifier.
157+
* Should not be checked into source control because the subscription identifier is sensitive information.
164158

165-
**MSDeploy:**
159+
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 user name and password.
166160

167-
```dotnetcli
168-
dotnet publish WebApplication.csproj /p:PublishProfile=<MsDeployProfileName> /p:Password=<DeploymentPassword>
169-
```
170-
171-
```dotnetcli
172-
dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<MsDeployProfileName> /p:Password=<DeploymentPassword>
173-
```
174-
175-
**MSDeploy package:**
176-
177-
```dotnetcli
178-
dotnet publish WebApplication.csproj /p:PublishProfile=<MsDeployPackageProfileName>
179-
```
161+
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).
180162

181-
```dotnetcli
182-
dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile=<MsDeployPackageProfileName>
183-
```
163+
`dotnet publish` and `dotnet build`:
184164

185-
In the preceding examples:
165+
* 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.
166+
* 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.
186167

187-
* `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.
188-
* Don't pass `DeployOnBuild` to the `dotnet publish` command.
168+
Don't pass `DeployOnBuild` to the `dotnet publish` command.
189169

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

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

207-
When publishing with a profile named *FolderProfile*, use any of the following commands:
174+
When publishing with a profile named `FolderProfile`, use any of the following commands:
208175

209176
```dotnetcli
210177
dotnet publish /p:Configuration=Release /p:PublishProfile=FolderProfile
@@ -225,33 +192,11 @@ The .NET CLI's [dotnet build](/dotnet/core/tools/dotnet-build) command calls `ms
225192

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

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

252197
In the preceding example:
253198

254-
* 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.
199+
* 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.
255200
* 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.
256201
* Using the .NET CLI:
257202

@@ -271,49 +216,18 @@ In the preceding example:
271216
272217
## Publish to an MSDeploy endpoint from the command line
273218
274-
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.
275-
276-
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).
219+
See [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish).
277220
278-
MSBuild uses the following command syntax:
279-
280-
```bash
281-
msbuild {PATH}
282-
/p:DeployOnBuild=true
283-
/p:PublishProfile={PROFILE}
284-
/p:Username={USERNAME}
285-
/p:Password={PASSWORD}
286-
```
221+
<!-- As of Nov 2024
222+
On the Azure Portal, settings/configuration, enable SCM and FTB basic auth publishing.
223+
Download the publish profile and get the username and password.
287224
288-
* `{PATH}`: Path to the app's project file.
289-
* `{PROFILE}`: Name of the publish profile.
290-
* `{USERNAME}`: MSDeploy username. The `{USERNAME}` can be found in the publish profile.
291-
* `{PASSWORD}`: MSDeploy password. Obtain the `{PASSWORD}` from the *{PROFILE}.PublishSettings* file. Download the *.PublishSettings* file from either:
292-
* **Solution Explorer**: Select **View** > **Cloud Explorer**. Connect with your Azure subscription. Open **App Services**. Right-click the app. Select **Download Publish Profile**.
293-
* Azure portal: Select **Get publish profile** in the web app's **Overview** panel.
225+
Using the default publish profile, the following command publishes to an MSDeploy endpoint:
294226
295-
The following example uses a publish profile named *AzureWebApp - Web Deploy*:
227+
msbuild /p:Configuration=Release /p:DeployOnBuild=true /p:UserName="<UN> /p:Password="pw"
296228
297-
```bash
298-
msbuild "AzureWebApp.csproj"
299-
/p:DeployOnBuild=true
300-
/p:PublishProfile="AzureWebApp - Web Deploy"
301-
/p:Username="$AzureWebApp"
302-
/p:Password=".........."
303-
```
304-
305-
A publish profile can also be used with the .NET CLI's [dotnet msbuild](/dotnet/core/tools/dotnet-msbuild) command from a Windows command shell:
306-
307-
```dotnetcli
308-
dotnet msbuild "AzureWebApp.csproj"
309-
/p:DeployOnBuild=true
310-
/p:PublishProfile="AzureWebApp - Web Deploy"
311-
/p:Username="$AzureWebApp"
312-
/p:Password=".........."
313-
```
314-
315-
> [!IMPORTANT]
316-
> The `dotnet msbuild` command is a cross-platform command and can compile ASP.NET Core apps on macOS and Linux. However, MSBuild on macOS and Linux isn't capable of deploying an app to Azure or other MSDeploy endpoints.
229+
If testing, delete the app or restore the basic auth settings to disabled.
230+
-->
317231
318232
## Set the environment
319233
@@ -445,7 +359,7 @@ The highlighted markup in the following example demonstrates:
445359
* Excluding the *wwwroot\Content* folder.
446360
* Excluding *Views\Home\About2.cshtml*.
447361

448-
[!code-xml[](visual-studio-publish-profiles/samples/Web1.pubxml?highlight=18-23)]
362+
[!code-xml[](visual-studio-publish-profiles/samples/Web1.pubxml?highlight=20-25)]
449363

450364
The preceding example uses the `ResolvedFileToPublish` item, whose default behavior is to always copy the files provided in the `Include` attribute to the published site. Override the default behavior by including a `<CopyToPublishDirectory>` child element with inner text of either `Never` or `PreserveNewest`. For example:
451365

@@ -462,14 +376,7 @@ For more deployment samples, see the [Web SDK README file](https://github.com/do
462376

463377
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:
464378

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

474381
## Publish to a server using an untrusted certificate
475382

@@ -494,6 +401,7 @@ Select the [Debug Console](https://github.com/projectkudu/kudu/wiki/Kudu-console
494401

495402
## Additional resources
496403

497-
* [Web Deploy](https://www.iis.net/downloads/microsoft/web-deploy) (MSDeploy) simplifies deployment of web apps and websites to IIS servers.
404+
* [Web SDK README file](https://github.com/dotnet/sdk/tree/main/src/WebSdk)
498405
* [Web SDK GitHub repository](https://github.com/dotnet/websdk/issues): File issues and request features for deployment.
406+
* [Web Deploy](https://www.iis.net/downloads/microsoft/web-deploy) (MSDeploy) simplifies deployment of web apps and websites to IIS servers.
499407
* <xref:host-and-deploy/iis/transform-webconfig>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<DeleteExistingFiles>false</DeleteExistingFiles>
8+
<ExcludeApp_Data>false</ExcludeApp_Data>
9+
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
10+
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
11+
<LastUsedPlatform>Any CPU</LastUsedPlatform>
12+
<PublishProvider>FileSystem</PublishProvider>
13+
<PublishUrl>\\r8\Release\AdminWeb</PublishUrl>
14+
<WebPublishMethod>FileSystem</WebPublishMethod>
15+
<_TargetId>Folder</_TargetId>
16+
</PropertyGroup>
17+
</Project>

0 commit comments

Comments
 (0)