61

I am creating a publishable package and when I navigate to obj\Debug\Package\PackageTmp directory, I am seeing the web.config's connection string is replaced by a replacable token, and I simply don't want that. I won't be using publishing batch files or anything, I'll be copying the files in the directory (I'm using the publishing package system only to get rid of lots of dynamically generated files while I'm testing my project and get the fresh/original file tree of my project) I don't want those web.config tokens and transforms etc, I just want my web.config file to be copied just like any other file. How do I achieve that? I've seen the /p:AutoParameterizationWebConfigConnectionStrings=False method for the commad line but I'm not using the command line, I am using the GUI to create the package. How will I stop web.config from changing the connection string to a token?

And before you say: Yes, I know that I can copy the original web.config from my original directory, but I don't want to deal with this and that, I want to finish it with a single click as I'm testing the publish package and frequently re-creating the package.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

4 Answers4

107

You have to edit your .csproj file and in the Debug PropertyGroup you'll have to add the following:

<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>

I have the following on Release and ReleaseCERT Configurations in my Project.csproj (I've only added the AutoParameterizationWebConfigConnectionStrings line):

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '**Release**|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <!-- add the following line to avoid ConnectionString tokenization -->
    <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '**ReleaseCERT**|AnyCPU'">
    <OutputPath>bin\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <!-- add the following line to avoid ConnectionString tokenization -->
    <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
</PropertyGroup>
Andre Albuquerque
  • 1,881
  • 1
  • 18
  • 15
  • 2
    Thanks for the solution - any idea *why* we have to do this? – Mustafa Shabib Aug 09 '12 at 22:39
  • 2
    @Mustafakidd it's related to the msdeploy packaging invoked during whenever you build your project (using MSBuild). The ReplacableToken should be replaced only when deploying (using the TransformXml task in your .csproj/.vsproj. More info here: http://stackoverflow.com/questions/4750153/transforming-files-with-msdeploy) – Andre Albuquerque Aug 21 '12 at 09:32
  • An easier solution might be to add a dummy conn string transform to the Web.Debug.config or Web.Release.config. – Justin Feb 15 '13 at 15:39
  • 1
    @Justin the token appears exactly when you have a ConnectionString, in the original Web.config or in one of the transforms (Web.Debug.config, Web.Release.config, etc). In my case, I had different ConnectionStrings for each transform configuration. – Andre Albuquerque Feb 15 '13 at 21:54
  • You can also keep this setting in your pubxml file – abhijat_saxena Mar 02 '22 at 19:20
17

I had to do what the accepted answer said, but instead in the Properties/PublishProfiles/__THEPROFILE__.pubxml file rather than the .csproj file.

(this may because I'm using VS2012?)

Community
  • 1
  • 1
drzaus
  • 24,171
  • 16
  • 142
  • 201
5

I had a similar issue when I was trying to create a web project package externally for a WiX setup according to the Travis Illig instructions. I solved it by adding the AutoParameterizationWebConfigConnectionStrings=False to the MSBuild/@Properties:

<MSBuild Projects="%(ProjectReference.FullPath)"
         Targets="Package"
         Properties="Configuration=$(Configuration);Platform=AnyCPU;AutoParameterizationWebConfigConnectionStrings=False"
         Condition="'%(ProjectReference.WebProject)'=='True'"
Ryszard Dżegan
  • 24,366
  • 6
  • 38
  • 56
  • 2
    +1 This is the appropriate solution for this particular case, as it doesn't involve tinkering with the config of the deployed project, only the deployment logic. – Tom W Apr 09 '15 at 08:58
-2

I had to add the following in the Release condition section of my Project.csproj file:

<InsertAdditionalWebCofigConnectionStrings>False</InsertAdditionalWebCofigConnectionStrings>
Danikenan
  • 477
  • 5
  • 10
  • Didn't fix the issue. I think that the XML tag you provided may be misspelled. Seems like it should be spelled like this... InsertAdditionalWebConfigConnectionStrings, not InsertAdditionalWebCofigConnectionStrings Either way, this didn't work for me. – Grizzly Peak Software Jun 02 '17 at 17:45