Charles Sousa
Charles Sousa

Reputation: 47

ConfigSource in ConnectionStrings - WEB.config ASP.NET

I'm doing an automated publishing using VSTS, the whole process performs publishing on multiple servers, and each has its own specific settings in WEB.config. I was deleting WEB.config before I threw the publication files into the folder so I was not replacing the existing one, but this caused some problems.

The solution I found was to use additional files to complement WEB.config, so in AppSettings I used the file = "" attribute to link other settings from other archives called WebAppSettings.config.

This WebAppSettings.config files has None as a compilation action, so at the time of publication it is ignored and when the files are dropped into the folder, and it does not overlap the current one.

But when attempting to do the same with ConnectionStrings, using the configSource = "" attribute to indicate the WebConnectionStrings.config add-in file, it fails during the pruning because the build does not accept that the file has as compilation action other than Content, if I put None or additionalfiles, it simply says error that can not find the file.

Do you have any way around it? How to make WebConnectionStrings.config work with None? I figured it would work the same way as AppSettings. I could not find anything in my research to help with this WEB.config issue.

Publication is done with Pre views compiled using AspNetPreCompile MSBUILD Arguments:

/p:DeployOnBuild=true /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\" /p:WebPublishMethod=FileSystem /p:PrecompileBeforePublish=true /p:EnableUpdateable=false /p:DebugSymbols=false /p:WDPMergeOption=MergeAllOutputsToASingleAssembly /p:UseMerge=true /p:SingleAssemblyName=AppViews

WEB.config

[...]

<connectionStrings configSource="WebConnectionStrings.config"></connectionStrings>

<appSettings file="WebAppSettings.config">
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="MvcFlashMessages/IsClosable" value="true" />
    <add key="MvcFlashMessages/InnerCssClass" value="alert" />
</appSettings>

[...]

Upvotes: 0

Views: 536

Answers (1)

raterus
raterus

Reputation: 2089

Build-action of "Content" is correct, you don't want to change that. It appears your underlying problem here is how to setup your project to support VSTS build/releases.

During the VSTS build creation, any .config files with

<DependentUpon>Web.config</DependentUpon>

are going to be deleted as part of the build process. You don't want that if you are later going to transform the files during the release.

To get by this, you need to remove the DependentUpon tag in the project (.csproj/.vbproj) file. This will keep all the config files for various environments all visible in solution explorer, don't worry though, it doesn't break anything.

I'd also make the suggestion that splitting up the files are not necessary in this case, you can get this all back to a single Web.config file.

Upvotes: 1

Related Questions