CZEMacLeod / MSBuild.SDK.SystemWeb

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.
MIT License
151 stars 8 forks source link

Environment-specific Web.config files do not end up in a deployment package #43

Closed stevenvolckaert closed 1 year ago

stevenvolckaert commented 1 year ago

I'm using MSBuild.SDK.SystemWeb version 4.0.79 in one of our ASP.NET applications, where I have included some environment-specific Web.config files, which contain XDT transforms:

image

They are in the csproj file as follows:

image

I'm using an Azure DevOps pipeline to build and publish the project with MSBuild. The publish task is using the WebPublish MSBuild target:

image

For some reason, the files Web.Release.Development.config and Web.Release.Staging.config do not end up in the output directory of the WebPublish MSBuild target; so they also do not appear in the build artifact.

Does anyone have an idea why this is?

This is not urgent, as I've worked around this issue by renaming the files to *.config.xml.

Thanks for looking into this!

CZEMacLeod commented 1 year ago

Hi @stevenvolckaert This is a known issue with the current SDK. Publish only includes content if the DependentUpon field is not set (so it is not nested in the UI). The SDK already includes non-configuration web.*.config files as content, but it nests them. The 'problem' is here: https://github.com/CZEMacLeod/MSBuild.SDK.SystemWeb/blob/afc4c08d291166886f39ff4ebfd04961acf28944/src/MSBuild.SDK.SystemWeb/Sdk/MSBuild.SDK.SystemWeb.DefaultItems.props#L19

Add the following to your project file and it should resolve the issue.

  <ItemGroup>
    <Content Update="Web.*.config">
      <DependentUpon></DependentUpon>
    </Content>
  </ItemGroup>

I think that the nesting can be done a different way - perhaps a virtual publishing node and some custom display xaml - but that is not something I am very familiar with (yet).

stevenvolckaert commented 1 year ago

Hi @CZEMacLeod! Thank you for your answer.

I confirm adding <Content Update="Web.*.config" DependentUpon="" /> worked; the files are now part of package when publishing.

I'll close this issue as you mentioned it is a known issue, so this issue is probably a duplicate.