How to extend msdeploy/publishing pipeline for .NET Core apps

685 Views Asked by At

Old style/.NET Framework webapps in Visual Studio have a publish pipeline that could be customized. For example, a Parameters.xml file could be specified, like so:

  <PropertyGroup>
    <WebAppPackageConfigDir Condition=" '$(WebAppPackageConfigDir)' == '' ">$(MSBuildProjectDirectory)\Package</WebAppPackageConfigDir>
    <ProjectParametersXMLFile>$(WebAppPackageConfigDir)\Parameters.xml</ProjectParametersXMLFile>
  </PropertyGroup>

so that when the MSDeploy package is built, the MSDeploy parameters defined therein are incorporated into the package. The Web Processing Pipeline (mostly defined in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets) supports customizing the MSDeploy package in multiple ways - for example, package parameters can be defined in a file or in an MSBuild <ItemGroup>.

In SDK style webapps (eg ASP.NET Core webapps), a "new" publishing pipeline is used starting in eg C\Program Files\dotnet\sdk\2.1.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets. This pulls in additional targets files depending on the <PublishProtocol> value, eg C\Program Files\dotnet\sdk\2.1.2\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeploy.targets for PublishProtocol=MSDeploy or .\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets for PublishProtocol=MSDeployPackage. Both files define a _CreateParametersFiles target as:

  <!--
  ***********************************************************************************************
  TARGET : _CreateParameterFiles
  ***********************************************************************************************
 -->

  <Target Name="_CreateParameterFiles">

    <ItemGroup>
      <MsDeployDeclareParameters Remove="@(MsDeployDeclareParameters)" />

      <MsDeployDeclareParameters Include="IIS Web Application Name" >
        <Kind>ProviderPath</Kind>
        <Scope>IisApp</Scope>
        <Match>$(PublishIntermediateOutputPath)</Match>
        <Description></Description>
        <DefaultValue>$(DeployIisAppPath)</DefaultValue>
        <Value>$(DeployIisAppPath)</Value>
        <Tags>IisApp</Tags>
        <Priority></Priority>
        <ExcludeFromSetParameter>false</ExcludeFromSetParameter>
      </MsDeployDeclareParameters>
    </ItemGroup>

    <ItemGroup Condition="'@(_EFSQLScripts)' != ''">
      <MsDeployDeclareParameters Include="%(_EFSQLScripts.DBContext)">
        <Kind>ProviderPath</Kind>
        <Scope>dbfullsql</Scope>
        <Match>%(_EFSQLScripts.Identity)</Match>
        <Description></Description>
        <DefaultValue>%(_EFSQLScripts.ConnectionString)</DefaultValue>
        <Value>%(_EFSQLScripts.ConnectionString)</Value>
        <Tags>dbfullsql</Tags>
        <Priority></Priority>
        <ExcludeFromSetParameter>false</ExcludeFromSetParameter>
      </MsDeployDeclareParameters>
    </ItemGroup>

    <CreateParameterFile
      Parameters="@(MsDeployDeclareParameters)"
      DeclareSetParameterFile="$(_MSDeployParametersFilePath)"
      IncludeDefaultValue="True"
      OptimisticParameterDefaultValue="$(EnableOptimisticParameterDefaultValue)"
      SetParameterFile="$(_MSDeploySetParametersFilePath)"
      GenerateFileEvenIfEmpty="True" />
  </Target>

It appears that there's no support for customizing deploy parameters. Similarly, the <Target Name="_CreateManifestFiles"> target appears to prohibit customization.

The WPP (Web Publishing Pipeline - the previous implementation) is/was clunky, but there were articles/blog posts about how to customize it. With ASP.NET Core, there is no mention of customizing or extending the deploy process, that I can find. I did find a Channel 9 Video on ASP.NET Publishing, but it seems outdated - it applies to VS 2017 with the project.json and powershell scripts used for deployment, and it appears that was scrapped in favor of MSBuild targets.

I also did find https://github.com/aspnet/websdk/blob/dev/README.md#microsoftnetsdkpublish, which documents a few parts of the msdeploy settings that can be changed, but I would still state that there is no support for extending the pipeline.

I'm interpreting the lack of available information to mean "figure it out yourself", which is challenging when dealing with MSBuild and MSDeploy. Has anyone had any success customizing the deploy pipeline for ASP.NET Core webapps?

0

There are 0 best solutions below