See the question and my original answer on StackOverflow

What you can do is modify the project file and add an MsBuild Target.

The target can use a Custom Inline Task, a task with its source code integrated into the project file.

So to add this task:

1) unload the project (right click on project node, select "Unload Project")

2) edit the project file (right click on project node, select "Edit ")

3) add the following to the project file (for example to the end) and reload it, now when you build, the config file will be modified accordingly.

<Project ...>
  ...
    <Target Name="AfterBuild">
      <RegexReplace FilePath="$(TargetDir)$(TargetFileName).config" Input="setAtBuild" Output="$(SolutionPath)" />
    </Target>
    <UsingTask TaskName="RegexReplace" TaskFactory="CodeTaskFactory" AssemblyName="Microsoft.Build.Tasks.Core" >
      <ParameterGroup>
        <FilePath Required="true" />
        <Input Required="true" />
        <Output Required="true" />
      </ParameterGroup>
      <Task>
        <Using Namespace="System.Text.RegularExpressions"/>
        <Code Type="Fragment" Language="cs"><![CDATA[
                File.WriteAllText(FilePath, Regex.Replace(File.ReadAllText(FilePath), Input, Output));
            ]]></Code>
      </Task>
    </UsingTask>
</Project>

Here, I've defined Output to use a Visual Studio's MSBuild Property named SolutionPath, but you can reuse this RegexReplace task and update Input and Output parameters to various needs.