I am playing around with creating a T4 template for the “DDL Generation Template option” (model first) process in Visual Studio 2010 RC. Is it possible to retrieve the connection string that is associated with that process? If I right click on the .edmx file and choose “Generate Database from Model…” I have the option of choosing a data connection. That connection string is saved to the app.config (assuming that the option is checked). So I am wondering if it is possible to retrieve that connection string inside the T4 template. I would like to generate different information from the template based on the connection string.
More generally, is it possible to get any context information in this situation? So far, the only thing I have successfully retrieved is the .NET data provider name.
Note – I have studied the ideas provided by Craig but am only getting the name of the IDE (devenv.exe), which quite possibly means I am just doing something wrong.
Well, the EF connection string will always have the same name as the model, right? The DB connection string will be embedded in the EF connection string. So I’d say you should be able to get it, at least indirectly, via the EF connection string.
Because you’re not running in the assembly, have to specify the config file name.
So it would be something like:
Note that
name, here, is supposed to be an EXE name. But in the IDE, your config fine is going to be calledApp.configrather thanMyApp.dll.config. So you may have to play around with this to get it to work — try using “App” as the EXE name!Worst case is open it as a file and then use the config manager.