uniquelau
uniquelau

Reputation: 1368

Include web.release.config in Web Deploy output

By default when publishing a Web project using MSBuild/Visual Studio the config transforms are applied.

I would like to include the config transforms within the output.

Input

web.config  
web.Debug.config   
web.Release.config  

Default Output

web.config

Desired output

web.config  
web.Debug.config   
web.Release.config  

Upvotes: 2

Views: 1336

Answers (3)

Richard Hubley
Richard Hubley

Reputation: 2320

I was using Azure Dev Ops Server, and I wanted to run the Release transform on build, but also have the possibility to run additional transforms per pipeline target. In my case to change the SessionDb connection string

I added /p:MarkWebConfigAssistFilesAsExclude=false to the build parameters

I set my web.Prod.config to <CopyToOutputDirectory>Always</CopyToOutputDirectory>

I was still getting a NullReference exception when doing the transform. I had to remove

<compilation xdt:Transform="RemoveAttributes(debug)" />

from the prod config transform because that property was removed with the release config transform.

Upvotes: 0

Mr Qian
Mr Qian

Reputation: 23838

Include web.release.config in Web Deploy output

By default, when publishing a website, VS does not package web.debug.config and web.release.config but only the web.config.

To achieve what you want, you can add a custom target into publishprofile.pubxml to include these extra files.

Please try this:

<Target Name="CustomCollectFiles">
          <ItemGroup>
            <AdditionFiles Include="xxxxxxxxxxx\Web.Debug.config;xxxxxxxxx\Web.Release.config">
            </AdditionFiles>
            <FilesForPackagingFromProject Include="%(AdditionFiles.Identity)">
               <DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
            </FilesForPackagingFromProject>
          </ItemGroup>
     </Target>
     <PropertyGroup>
          <CopyAllFilesToSingleFolderForPackageDependsOn>
               CustomCollectFiles;
               $(CopyAllFilesToSingleFolderForPackageDependsOn);
          </CopyAllFilesToSingleFolderForPackageDependsOn>

          <CopyAllFilesToSingleFolderForMsdeployDependsOn>
               CustomCollectFiles;
               $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
          </CopyAllFilesToSingleFolderForMsdeployDependsOn>
     </PropertyGroup>

And then you will find these files in the Publish folder when you finishing Publish step.

Hope it could help you.

Upvotes: 3

uniquelau
uniquelau

Reputation: 1368

Update the files Build Action to Content using Visual Studio (e.g. right click, properties)

enter image description here

The Publish tasks will still transform the files, so we need to tell MSBuild, that we do not want to transform those files when publishing.

This can be achieved by passing the following parameters into MSBuild:

/p:ProfileTransformWebConfigEnabled=false /p:MarkWebConfigAssistFilesAsExclude=false

If you are working within Visual Studio, you test this behavior by adding these properties to a folder publish profile PublishProfile.xml

<!-- Disable Web.config Transforms -->
<ProfileTransformWebConfigEnabled>false</ProfileTransformWebConfigEnabled>
<MarkWebConfigAssistFilesAsExclude>false</MarkWebConfigAssistFilesAsExclude>

Upvotes: 5

Related Questions