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
* 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]>
By [Sayed Ibrahim Hashimi](https://github.com/sayedihashimi) and [Rick Anderson](https://twitter.com/RickAndMSFT)
16
16
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)
18
24
19
25
The `dotnet new mvc` command produces a project file containing the following root-level [\<Project> element](/visualstudio/msbuild/project-element-msbuild):
20
26
@@ -24,7 +30,7 @@ The `dotnet new mvc` command produces a project file containing the following ro
24
30
</Project>
25
31
```
26
32
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.
28
34
29
35
`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.
30
36
@@ -92,7 +98,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
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.
104
110
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:
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.
117
123
124
+
See the [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish) readme file for more information.
125
+
118
126
## Publish profiles
119
127
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.
121
129
122
130
Create a publish profile in Visual Studio by choosing one of the following paths:
123
131
124
132
* Right-click the project in **Solution Explorer** and select **Publish**.
125
133
* Select **Publish {PROJECT NAME}** from the **Build** menu.
126
134
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:
128
136
129
-
* Azure App Service
130
-
* Azure App Service on Linux
131
-
* Azure Virtual Machines
137
+
* Azure
138
+
* Docker Container Registry
132
139
* Folder
133
140
* IIS, FTP, Web Deploy (for any web server)
134
141
* Import Profile
@@ -139,72 +146,32 @@ When the **Folder** publish target is selected, specify a folder path to store t
139
146
140
147
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.
141
148
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:
143
150
144
151
* Contains publish configuration settings and is consumed by the publishing process.
145
152
* Can be modified to customize the build and publish process.
146
153
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:
* Should not be checked into source control because the subscription identifier is sensitive information.
164
158
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.
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).
* 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.
186
167
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.
189
169
190
170
For more information, see [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish).
191
171
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
-
205
172
## Folder publish example
206
173
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:
* 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.
255
200
* 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.
256
201
* Using the .NET CLI:
257
202
@@ -271,49 +216,18 @@ In the preceding example:
271
216
272
217
## Publish to an MSDeploy endpoint from the command line
273
218
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).
277
220
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.
287
224
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:
294
226
295
-
The following example uses a publish profile named *AzureWebApp - Web Deploy*:
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
+
-->
317
231
318
232
## Set the environment
319
233
@@ -445,7 +359,7 @@ The highlighted markup in the following example demonstrates:
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:
451
365
@@ -462,14 +376,7 @@ For more deployment samples, see the [Web SDK README file](https://github.com/do
462
376
463
377
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:
0 commit comments