diff --git a/aspnetcore/host-and-deploy/visual-studio-publish-profiles.md b/aspnetcore/host-and-deploy/visual-studio-publish-profiles.md index 2f8f350ed296..ad90bb827010 100644 --- a/aspnetcore/host-and-deploy/visual-studio-publish-profiles.md +++ b/aspnetcore/host-and-deploy/visual-studio-publish-profiles.md @@ -14,7 +14,13 @@ uid: host-and-deploy/visual-studio-publish-profiles By [Sayed Ibrahim Hashimi](https://github.com/sayedihashimi) and [Rick Anderson](https://twitter.com/RickAndMSFT) -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 . +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 . + +For the most current and detailed information on: + +* Publishing with Visual studio, see [Overview of Visual Studio Publish](/visualstudio/deployment/publish-overview) +* MSBuild, see [MSBuild](/visualstudio/msbuild/msbuild-introduction) +* Publishing with MSBuild, see [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish) The `dotnet new mvc` command produces a project file containing the following root-level [\ element](/visualstudio/msbuild/project-element-msbuild): @@ -24,7 +30,7 @@ The `dotnet new mvc` command produces a project file containing the following ro ``` -The preceding `` 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. +The preceding `` 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. `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. @@ -92,7 +98,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. Web1 -> C:\Webs\Web1\bin\Debug\{TARGET FRAMEWORK MONIKER}\publish\ ``` -The default publish folder format is *bin\Debug\\{TARGET FRAMEWORK MONIKER}\publish\\*. For example, *bin\Debug\netcoreapp2.2\publish\\*. +The default publish folder format is `bin\Debug\{TARGET FRAMEWORK MONIKER}`. For example, `bin\Release\net9.0\` The following command specifies a `Release` build and the publishing directory: @@ -102,7 +108,7 @@ dotnet publish -c Release -o C:\MyWebs\test 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. -MSBuild properties can be passed using either of the following formats: +[MSBuild properties](/visualstudio/msbuild/msbuild-command-line-reference) can be passed using either of the following formats: * `-p:=` * `/p:=` @@ -115,20 +121,21 @@ dotnet publish -c Release /p:PublishDir=//r8/release/AdminWeb 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. +See the [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish) readme file for more information. + ## Publish profiles -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. +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. Create a publish profile in Visual Studio by choosing one of the following paths: * Right-click the project in **Solution Explorer** and select **Publish**. * Select **Publish {PROJECT NAME}** from the **Build** menu. -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: +The **Publish** tab of the app capabilities page is displayed. Several publish targets are available, including: -* Azure App Service -* Azure App Service on Linux -* Azure Virtual Machines +* Azure +* Docker Container Registry * Folder * IIS, FTP, Web Deploy (for any web server) * Import Profile @@ -139,72 +146,32 @@ When the **Folder** publish target is selected, specify a folder path to store t 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. -Visual Studio's publish tool produces a *Properties/PublishProfiles/{PROFILE NAME}.pubxml* MSBuild file describing the publish profile. The *.pubxml* file: +Visual Studio's publish tool produces a `Properties/PublishProfiles/{PROFILE NAME}.pubxml` MSBuild file describing the publish profile. The *.pubxml* file: * Contains publish configuration settings and is consumed by the publishing process. * Can be modified to customize the build and publish process. -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. - -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. - -For an overview of how to publish an ASP.NET Core web app, see . 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). - -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. +When publishing to an Azure target, the *.pubxml* file: -**Folder (works cross-platform):** - -```dotnetcli -dotnet publish WebApplication.csproj /p:PublishProfile= -``` - -```dotnetcli -dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile= -``` +* Contains the Azure subscription identifier. +* Should not be checked into source control because the subscription identifier is sensitive information. -**MSDeploy:** +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. -```dotnetcli -dotnet publish WebApplication.csproj /p:PublishProfile= /p:Password= -``` - -```dotnetcli -dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile= /p:Password= -``` - -**MSDeploy package:** - -```dotnetcli -dotnet publish WebApplication.csproj /p:PublishProfile= -``` +For an overview of how to publish an ASP.NET Core web app, see . 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). -```dotnetcli -dotnet build WebApplication.csproj /p:DeployOnBuild=true /p:PublishProfile= -``` +`dotnet publish` and `dotnet build`: -In the preceding examples: +* 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. +* 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. -* `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. -* Don't pass `DeployOnBuild` to the `dotnet publish` command. +Don't pass `DeployOnBuild` to the `dotnet publish` command. For more information, see [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish). -Add a publish profile to the project's *Properties/PublishProfiles* folder with the following content: - -```xml - - - Kudu - nodewebapp - username - password - - -``` - ## Folder publish example -When publishing with a profile named *FolderProfile*, use any of the following commands: +When publishing with a profile named `FolderProfile`, use any of the following commands: ```dotnetcli 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 The following folder publish profile was created with Visual Studio and publishes to a network share: -```xml - - - - - FileSystem - FileSystem - Release - Any CPU - - True - False - netcoreapp1.1 - c30c453c-312e-40c4-aec9-394a145dee0b - \\r8\Release\AdminWeb - False - - -``` +[!code-xml[](visual-studio-publish-profiles/samples/FolderProfile.pubxml)] In the preceding example: -* The `` property is present merely to satisfy an XML schema requirement. The `` 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. +* The `` property is present to satisfy an XML schema requirement. The `` 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. * The `` property is set to `Release`. When publishing from Visual Studio, the value of `` is set using the value when the publish process is started. `` 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. * Using the .NET CLI: @@ -271,49 +216,18 @@ In the preceding example: ## Publish to an MSDeploy endpoint from the command line -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. - -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). +See [Microsoft.NET.Sdk.Publish](https://github.com/dotnet/sdk/tree/main/src/WebSdk#microsoftnetsdkpublish). -MSBuild uses the following command syntax: - -```bash -msbuild {PATH} - /p:DeployOnBuild=true - /p:PublishProfile={PROFILE} - /p:Username={USERNAME} - /p:Password={PASSWORD} -``` + ## Set the environment @@ -445,7 +359,7 @@ The highlighted markup in the following example demonstrates: * Excluding the *wwwroot\Content* folder. * Excluding *Views\Home\About2.cshtml*. -[!code-xml[](visual-studio-publish-profiles/samples/Web1.pubxml?highlight=18-23)] +[!code-xml[](visual-studio-publish-profiles/samples/Web1.pubxml?highlight=20-25)] 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 `` child element with inner text of either `Never` or `PreserveNewest`. For example: @@ -462,14 +376,7 @@ For more deployment samples, see the [Web SDK README file](https://github.com/do 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: -```xml - - - - - - -``` +[!code-xml[](visual-studio-publish-profiles/samples/TP_before.pubxml?highlight=30-35)] ## Publish to a server using an untrusted certificate @@ -494,6 +401,7 @@ Select the [Debug Console](https://github.com/projectkudu/kudu/wiki/Kudu-console ## Additional resources -* [Web Deploy](https://www.iis.net/downloads/microsoft/web-deploy) (MSDeploy) simplifies deployment of web apps and websites to IIS servers. +* [Web SDK README file](https://github.com/dotnet/sdk/tree/main/src/WebSdk) * [Web SDK GitHub repository](https://github.com/dotnet/websdk/issues): File issues and request features for deployment. +* [Web Deploy](https://www.iis.net/downloads/microsoft/web-deploy) (MSDeploy) simplifies deployment of web apps and websites to IIS servers. * diff --git a/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/FolderProfile.pubxml b/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/FolderProfile.pubxml new file mode 100644 index 000000000000..075a213d03a9 --- /dev/null +++ b/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/FolderProfile.pubxml @@ -0,0 +1,17 @@ + + + + + false + false + true + Release + Any CPU + FileSystem + \\r8\Release\AdminWeb + FileSystem + <_TargetId>Folder + + \ No newline at end of file diff --git a/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/TP_before.pubxml b/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/TP_before.pubxml new file mode 100644 index 000000000000..09bcea1d2fea --- /dev/null +++ b/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/TP_before.pubxml @@ -0,0 +1,36 @@ + + + + + MSDeploy + /subscriptions/SomeGuid/resourcegroups/TP_RG/providers/Microsoft.Web/sites/TP22 + TP_RG + AzureWebSite + Release + Any CPU + https://tp22.azurewebsites.net + true + false + GuidHere + something.scm.azurewebsites.net:443 + myDeploysIISpath + + true + WMSVC + true + true + + <_SavePWD>false + <_DestinationType>AzureWebSite + false + + + + + + + + diff --git a/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/Web1.pubxml b/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/Web1.pubxml index 852b9152d212..6c9e0bd27360 100644 --- a/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/Web1.pubxml +++ b/aspnetcore/host-and-deploy/visual-studio-publish-profiles/samples/Web1.pubxml @@ -10,7 +10,9 @@ True False - afa9f185-7ce0-4935-9da1-ab676229d68a + + + bin\Release\PublishOutput False