MSBuild Web Deploy Does Not Update Connection Strings

I am currently trying to start the deployment process on my production server. I am currently using web deployment and profile publishing to achieve this, and everything works fine for me, except for updating the connection strings to match the production server.

I use:

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

to create a publication package, and:

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

So it works, it packs and then sends it to the server in order and configures IIS correctly, but points to the wrong database.

My publication profile looks like this:

 <?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 great when publishing directly from VS2012, and not through the command line. Is there a switch or option that I am missing in my msbuild call?

It does not work correctly, as in my myProj.SetParameters.xml file, the connection strings shown here are incorrect. If I manually changed them to the correct connection strings, the web.xml file will be correct on the production server after it is deployed. How to get the correct line in a SetParameters file? Any help would be greatly appreciated.

+5
source share
3 answers

In the end, to get around this, in Visual Studio I created the Parameters.xml file in the root of the project, which contains the connection string values โ€‹โ€‹that will be used on the production server. They are selected and used instead of the default values.

The Parameters.xml file looks like this:

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

Just add as many as you need and obviously fill in the required attributes

+3
source

My DefaultConnection has also not been updated. It turned out that I had to delete the MyProject> PublishProfiles.pubxml file.

Then, trying to publish a newly built project, he asked me to connect to the azure window and download the publication profile.

Despite the fact that this wizard has a flag with the ability to disable the redefinition of the DefaultConnection line from the one that is unchecked with the publication profile, unchecking it had no effect. He continued to rewrite the line.

So, in the azure control panel (portal), I clicked the websites> My website> Configure

Scroll down to the connection strings and you can show the hidden connection string. I simply deleted it by pressing x and then encoded the correct one in my web configuration.

Then I deleted .pubxml again and went through the wizard again. Now there is no connection string that extends with the publication profile.

0
source

The .pubxml file of my publication profile (located in Project \ Properties \ PublishProfiles) was corrupted with additional duplicate nodes "Connection String DefaultConnection-Web.config". The connection string was updated correctly after I deleted the extra nodes.

0
source

All Articles