5

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.

5
  • Are you sure your first command is generating a package? Your publish profile has a WebPublishMethod of MSDeploy, not Package. Commented Feb 14, 2013 at 4:22
  • It is generating the package. You can either deploy with MSDeploy, or the method which I am using though Commented Feb 14, 2013 at 8:30
  • Alternative you could use web.config transformations for the connection string replace and choose the configuration to publish when executing MSBuild. Commented Feb 14, 2013 at 10:16
  • @Thewads - That seems strange to me. Packages should only be generated if CreatePackageOnPublish is true or if deploying to a publish profile with a WebPublishMethod of Package. Are you sure there aren't other properties being set? Commented Feb 14, 2013 at 10:59
  • @RichardSzalay I am just running the commands exactly as detailed above. If I take out DeployOnBuild=true then the packages are not built Commented Feb 14, 2013 at 13:35

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

My DefaultConnection was not updating either. It turned out that I had to delete the MyProject > PublishProfiles .pubxml file.

Then when attempting to publish the newly built project it asked me to connect to azure and download the publishing profile.

Even though that wizard has a checkbox with the option to turn off overriding the DefaultConnection string with the one pulled down with the publishing profile, unchecking it had no effect. It continued to overwrite the string.

So in the azure control panel (portal) I clicked Websites > My Website > Configure

Scroll down to connection strings and you can show the hidden connection string. I just removed it by hitting the x and then hardcoded the correct one in my web config.

I then removed the .pubxml again and went through the wizard again. Now there is not connectionstring being pulled down with the publish profile.

Comments

0

My Publish Profile .pubxml file (found in Project\Properties\PublishProfiles) had become corrupt with extra duplicate "DefaultConnection-Web.config Connection String" nodes. The connection string updated correctly after I deleted the extra nodes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.