How do you use the --connectionStringConfigPath for FluentMigrator when using the MSBuild runner?
The documentation says
Connection (required)
The connection string to the server and database you want to execute
your migrations against. This can be a full connection string or the
name of the connection string stored in a config file.
When specifying a named connection string, FluentMigrator searchs for
it in this order:
The specified config file via --connectionStringConfigPath parameter
Target assembly’s config file
Machine.config config file
I was not able to get this to work and couldn't find any examples of usage with FluentMigrator's MSBuild runner.
The connectionStringConfigPath parameter is used in conjuction with the Connection parameter. The Connection parameter specifies the name of the connection string.
This is an example of the migrate task:
<Migrate Database="sqlserver2012"
Connection="SRVConnectionString"
ConnectionStringConfigPath="db.config"
Target="./Migrations/bin/Debug/Migrations.dll">
</Migrate>
And this is the db.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<clear />
<add name="SRVConnectionString" connectionString="server=SQLEXPRESS;uid=test;pwd=test;database=Test"/>
</connectionStrings>
</configuration>
I will update the wiki with this example.
Related
I have a build step in teamcity which allows me to replace web.config values with web.release.config values. I would like to add one more step - pass some parameter from teamcity to web.config. In my case it will be release version, which is part of connection string. The best idea I have is just to have some powershell script which will replace text in some file (web.config). Are there any better options?
Example web config
<add key="Version" value="Replace me, please from teamcity"/>
<add key="some key" value="example 2. version as part of some value #VERSION"/>
You could use File Content Replacer.
Instead of making the creation of the web.config in release dependent of TeamCity, you can use the web.config transformation syntax
ie: To create a specific connection string:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
Have been trying to apply a transformation to one of my config files in Visual Studio 2010
The target file starts like this:
forms.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<formsDataProvider type="Sitecore.Forms.Data.DataProviders.WFMDataProvider,Sitecore.Forms.Core">
<param desc="connection string">connection string goes here</param>
</formsDataProvider>
...
The transformation file is as follows:
forms.Staging.config
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<sitecore>
<formsDataProvider type="Sitecore.Forms.Data.DataProviders.WFMDataProvider,Sitecore.Forms.Core">
<param desc="connection string" xdt:Transform="Replace" xdt:Locator="Match(desc)">connection string for staging goes here</param>
</formsDataProvider>
</sitecore>
</configuration>
When the staging build runs on Octopus this is what's in the log:
DEBUG [XML Transformation] The expected namespace http://schemas.microsoft.com/XML-Document-Transform was not found in the transform file.
Have tried to remove the other xmlns attributes to no avail.
Said namespace is clearly on the transform file as an attribute in the configuration node. We have numerous other such files and transformations are applied fine. The Build Action for all transform files is set to Content.
Not sure if we can make Octopus log such messages as errors instead of Debug though.
Has anyone else had a similar problem?
Thanks in advance.
It looks like it might be trying to apply your forms.config as a transformation file instead of a target.
What do you have specified in the deployment step's Additional Transforms? Did you accidentally include forms.config itself?
I am using Web.config transforms to successfully create debug and release versions of the my web.config - this is working correctly.
I am interested to know whether there is a 'machine name' property to specify the current machine name which I can use in a debug URL, rather than hard-coding a specific machine name (using localhost isn't an option in the case), e.g.
<add name="XrmService" connectionString="http://$(ComputerName):5555/Service.svc" />
Are there any properties available using Web.config transforms? Similar to MSBuild's $(ComputerName) property?
I faced a similar issue, what I ended up doing is :
1) Added the following build target to the project file. (Which is an MSBuild script effectively)
<Target Name="AfterBuild">
<TransformXml Source="Web.config" Condition="Exists('Web.$(Computername).config') " Transform="Web.$(Computername).config" Destination="Web.config" />
</Target>
2) Added a Web.MyMachineName.config config transform file to the project. In your case it should look like this:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="XrmService"
connectionString="http://MyMachineName:5555/Service.svc"
xdt:Transform="SetAttributes"
xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
This has the benefit of running different transformations based on the machine name, without creating a separate build configuration. You can configure it to be debug only by specifying Condition="'$(Configuration)' == 'Debug'".
There is an Environment Variable that you can use. It is $(COMPUTERNAME).
Open a command window, type "set" (without the double quotes) and press Enter. You will see this Environment Variable somewhere at the top of the screen.
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="password"" 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="password"" Name="" />
<Object Type="DbDacFx">
<PreSource Path="Data Source=localhost;Initial Catalog=devDB;User ID=user;Password="password"" 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.
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
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.
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.
The scripts are generated correctly, i use multiple layers so the following commands are run into the Package Manager Console
Eg. When i added Email column to the table : "Owner"
Add-Migration AddEmailToOwner -StartupProjectName "FacturatieMVCv2.Data" -Verbose
--> Result:
Using NuGet project 'FacturatieMVCv2.Data'.
Target database is: 'FacturatieMVCv2.Data.Website.MyResellerContext' (DataSource: V-File \SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
Next command i use is:
Update-Database -StartupProjectName "FacturatieMVCv2.Data" -Verbose
--> Result:
Using NuGet project 'FacturatieMVCv2.Data'.
Target database is: 'FacturatieMVCv2.Data.Website.MyResellerContext' (DataSource: V-FILE\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
Applying explicit migrations: [201203080906140_AddDamnToOwner].
Applying explicit migration: 201203080906140_AddDamnToOwner.
ALTER TABLE [Owners] ADD [Damn] [nvarchar](max)
[Inserting migration history record]
My connectionstring in the App.Config is :
<parameter value="Server=V-FILE\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=sa;password=n*****3;" />
Although i specified the Initial catalog, it is targetting the wrong catalog. It's created / updated the database table named: FacturatieMVCv2.Data.Website.MyResellerContext .
Following is my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<!--<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />-->
<parameter value="Server=V-FILE02\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=sa;password=12345678;" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
In short, the Update-Database command, updated the wrong database.
Using the following command:
Update-Database -StartupProjectName "FacturatieMVCv2.Data" -Verbose -ConnectionString "Server=V-FILE\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=mydbuser;password=mydbpass;" -ConnectionProviderName "System.Data.SqlClient"
Fixed my problem.
SqlConnectionFactory adds the Initial Catalog to the value you provide. If you want to use a specific connection string for a context, you should add an entry in the connectionStrings section instead. E.g.
<connectionStrings>
<add name="MyResellerContext" connectionString="Server=V-FILE\SQLEXPRESS;Persist Security Info=True;Initial Catalog=ProductionReseller;uid=sa;password=12345678;" providerName="System.Data.SqlClient" />
</connectionStrings>
We store config variables in build configs to switch between these and ran into this issue; the solution was to Clean then explicitly Build.
To expand on that:
Our Db class (the one that inherits DbContext) has a Constructor like:
public Db()
#if AltDb
: base("AltDb")
#else
: base("Db")
#endif
{
}
So if the AltDb build var is defined, it's going to use the ConnectionString named AltDb; otherwise it uses the one named Db. In our Project configs, we have one named AltDb and all it does is define the AltDb build variable.
So we have those 2 connection strings defined in Web.Config:
<connectionStrings>
<add name="Db" connectionString="Initial Catalog=MyProj;Data Source=.\SQLEXPRESS...
<add name="AltDb" connectionString="Initial Catalog=Staging;Data Source...
So, when we want to update the alternate db, we SHOULD be able to just switch build configs and run update-database. This has worked in every project for years, but today it just wouldn't.
When I ran a Clean, then made sure this build config was selected and the startup Project was selected, and explicitly Built, magically it was solved - even though EF appears to build everything every time you run update-database.
I have no explanation as to why this would occur, but that's the cause and solution for us.