VSTS build: replace string in linked file before packing

345 views Asked by At

I use VSTS to build and release a solution with several aspnet projects. On the solution level is a folder with all database connection strings for dev/test and production. Those files are included in the projects as file links with the option to copy them always. Web.config transformation changes the configSource to the desired file based on the build configuration.

  <connectionStrings configSource="Configuration\ConnectionStrings.Development.config" xdt:Transform="Replace" />

All this works great. For the VSTS VSBuild task I have those arguments to generate a zip file for webdeploy

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)" /p:DefineConstants="$(CompilerConstants)"

Now comes my problem: I want to have the current project name as the Application Name in the connection string to see where queries come from in SQL Server profiler. I made it in the past with an additional build target

  <Target Name="ReplaceAppNamesInConnectionStrings">
    <FindAndReplaceInFile FileName="$(PublishDir)\configuration\ConnectionStrings.Development.config" SearchString="@@APPNAME@@" ReplacementString="$(ProjectName)" FileMustExist="False" />
    <FindAndReplaceInFile FileName="$(PublishDir)\configuration\ConnectionStrings.Production.config" SearchString="@@APPNAME@@" ReplacementString="$(ProjectName)" FileMustExist="False" />
  </Target>

How can I do this with VSTS? It seems that it always freshly copies the files from the linked source to the output just before creating the zip file and I could to get it replaced. I tried post build events or the VSTS replace token step.

0

There are 0 answers