How do I make entity-framework migrations use web.config transforms?
Asked Answered
P

1

5

When you apply any commands like

  • 'update-database'
  • 'add-migration'

The EF uses the connection string in your main web.config

even if you have configured web.debug.config and web.release.config with xml transformation

This means, I have to go in and risk forgetting to change my true web.config back prior to a release.

Pustule answered 4/3, 2014 at 13:17 Comment(1)
There are parameters for Update-Database called -ConnectionString and -ConnectionStringName. If you want to provide the connection string itself you can use the -ConnectionString parameter and just paste in the value. Either that or you could put all of your connection strings in the config file and use -ConnectionStringNameChaperon
F
4

I think the only way to run web.config transformations locally is to use MSBuild with the following parameters, where [YourTransformationConfiguration] is the name of the configuration to use, e.g. Debug or Release:

msbuild PathToProject /T:Package /P:Configuration=[YourTransformationConfiguration] /P:AutoParameterizationWebConfigConnectionStrings=False

The output of which will be available at:

[ProjectFolder]\obj\[YourTransformationConfiguration]\Package\PackageTmp

From here you can run migrate.exe on your assembly, which is similar to running the Update-Database PowerShell script. If you used Nuget, this will be in the tools folder of the EntityFramework package. I had some trouble getting this up and running, but there's a useful answer Stack Overflow answer here:

Getting Migrate.exe to work

Franciskus answered 5/3, 2014 at 5:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.