Hello followers, visitors and all. Today’s post is based on a rather frustrating subject on a Visual Studio feature that a lot of developers love to hate. Configuration transform. I have run into a particular nightmare issue twice now and I usually figure if something crops up more than once, it’s probably worth a post about it.
I’ll be briefly sharing what a transform is and why they are important. After that, I will explain the issues we were having and the headache I and another developer went through to solve the problem.
What does ‘Configuration Transform’ Mean?
Excellent question. Most likely, if you are at this article outside of a subscription, you already know what a transform is, but for my readers, I like to make sure anyone can understand it, even a novice.
A configuration transform is used when a developer needs several configuration settings to be different depending on their environment (development, UAT, production etc…) . The most common environmental change would be each one requiring a different database connection (different names, IP addresses and stuff like that). To accomplish this in a dynamic fashion, a technology called XDT transformations was used inside of Visual Studio. This standard allows you to use XML markup along with a few attributes Visual Studio / XDT is looking for and poof, you have a new configuration file.
If enough people request it, I might make a new post on how to do transforms in detail, but to keep this post on topic, I will end the lesson here. Next we will discuss the issue at hand.
So ‘Add Transform’ is Grayed out is it?
It sure was for us. In fact, it looked exactly like this.
So let us see what was done and where we went wrong. If you look in my drop down environments there is the usual debug and release, however, I have also added a Test configuration as well.
Now, when I set the Test up, I unchecked something EXTREMELY important.
I can only guess that Visual Studio under some condition unchecked it or we unchecked it. I’m thinking the first and not the latter. What this checkbox does is not only create the ‘solution’ configuration, but also the actual PROJECT configuration that does the work. This means that although we have a new “solution configuration name”, it doesn’t know what to assign it to (does it get .pdb files, does it need to do something special in certain configuration. The list could go on forever.
So Now What?
Good question! So now, the way to handle it is to create the actual configuration… duuhhhh. Lol, I can say this because it took us 2 days to get this all figured out.
First step is to open Configuration Manager back up and select Test as the active solution configuration from the drop down. This will show you what configuration (and in turn the configuration transform) is available for the application. Then, once there, you want to Select <New..> from the drop down under the Configuration column as shown below:
Next, you will see a new window that asks to create a project configuration. Name it the same Test you did before and set the “Copy settings to Debug”. Now, if you leave it like this, you will get the following error:
Now at first, when you didn’t get the context I just gave you about the differences in the ‘configuration types’, it would make you scratch your head. Well, since there is a solution configuration named Test, it isn’t lying, it’s just annoying. Why these thing just what I mean not what I say, I’ll never know :).
Any ways, if you unchecked the box that says Create new solution configurations, you should be all set when you click OK. Now, after doing that, lets see what happens when we right click the Web.config file.
YAYAYA it worked!
Until next time, Happy Coding 🙂