Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Web Deploy not updating connection strings

I am currently trying to get my deployment process up and running on my production server. Currently I am using the web deploy and publish profiles to achieve this, and I have everything working correctly, apart from the updating of connection strings to suit the production server.

I am using:

msbuild myProj.csproj /p:DeployOnBuild=true;PublishProfile=myProfile;Configuration=Release

to create the publish package, and the:

call myProj.deploy.cmd /Y /M:http://myServer/MSDeployAgentService -allowUntrusted /U:user /:Password

So this is working, it packages and then sends it to the server fine, and configures IIS correctly, but points to the wrong database.

My publishing profile looks like:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <MSDeployServiceURL>http://myserver</MSDeployServiceURL>
    <DeployIisAppPath>Website</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod>
    <UserName>user</UserName>
    <_SavePWD>True</_SavePWD>
    <PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="DBContext" Order="1" Enabled="False">
          <Destination Path="Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password=&quot;password&quot;" Name="" />
          <Object Type="DbCodeFirst">
            <Source Path="DBMigration" DbContext="myproj.Repositories.DBContext, myproj.Repositories" MigrationConfiguration="myproj.Repositories.Migrations.Configuration, myproj.Repositories" Origin="Configuration" />
          </Object>
        </ObjectGroup>
        <ObjectGroup Name="DefaultConnection" Order="2" Enabled="False">
          <Destination Path="Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password=&quot;password&quot;" Name="" />
          <Object Type="DbDacFx">
            <PreSource Path="Data Source=localhost;Initial Catalog=devDB;User ID=user;Password=&quot;password&quot;" includeData="False" />
            <Source Path="$(IntermediateOutputPath)AutoScripts\DefaultConnection_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
          </Object>
          <UpdateFrom Type="Web.Config">
            <Source MatchValue="Data Source=localhost;Initial Catalog=devDB;User Id=user;Password=password" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
          </UpdateFrom>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)DBContext-Web.config Connection String">
      <ParameterValue> Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"</ParameterValue>
    </MSDeployParameterValue>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)DefaultConnection-Web.config Connection String">
      <ParameterValue>Data Source=server;Initial Catalog=ProductionDB;User ID=user;Password="password"</ParameterValue>
    </MSDeployParameterValue>
  </ItemGroup>
</Project>

Annoyingly this works fine when Publishing directly from VS2012, just not via command line. Is there a switch or option I am missing from my msbuild call maybe?

It is not working correctly as in my myProj.SetParameters.xml file, the connection strings shown in there are wrong. If I manually change these to the correct connection strings, then the web.xml file is correct on the production server once deployed. How do I get the correct string into my SetParameters file? Any help would be greatly appreciated.

like image 397
Thewads Avatar asked Oct 22 '22 17:10

Thewads


1 Answers

In the end to get around this, in Visual Studio I created a Parameters.xml file in the root of project which holds the values of the connection strings to be used on the production server. These are picked up and used instead of the default values.

The Parameters.xml file looks like:

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
    <parameter name="DefaultConnection-Web.config Connection String"
        description=""
        defaultValue=""tags="" />

Just add as many as you require and obviously populate the attributes as required

like image 124
Thewads Avatar answered Nov 17 '22 12:11

Thewads