Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can different configurations manage files other than web.config in visual studio

I have a project that need to be tested and deployed for many different customers and those clients sometimes have different needs. It is an MVVC app, I use .net MVC but only for few bit and pieces, like some partial views and so on, everything else is a single page app using knockout.js.

So I have different web.config files but also I have a file that contains client side configuration, a .js file that is different for every customer.

Now if make different configurations in visual studio with configuration manager I get different web.config depending on the configuration I choose, and that is perfect.

But is there a way to have the same result for another file in the project?

like for example have a myfile.nightly.js and myfile.debug.js and so on. (those files contains configuration settings like the color of the page or the logo or the section to hide, that are proper to each different customer).

I tried this solution with prebuild events: http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx

but that is quite an hold post and I would like to know if there is something more actual with VS2012 for example

like image 646
Maurizio In denmark Avatar asked Oct 20 '22 09:10

Maurizio In denmark


1 Answers

This feature you are talking about (in the case of the web.config) is called Xml Transform. Unfortunately, Visual Studio only has support to transform web.config files automatically and nothing else.

SlowCheetah was created to transform other xml files of your choice, but it only works for Xml files. You can configure it to transform the files on each build (via a custom msbuild task) for instance.

I'm not aware of any solutions to transform javascript files though.

EDIT:

Perhaps you could build your own HttpHandler class to serve the customized js file? The link to the js file on the page would point to it, and it would serve a different js file for each customer, and the switching logic would be in the server.

I still feel this is a poor solution (but I may be biased because of Web Forms), and that ideally you would generate the page with this information already set, that is, the configuration could be in the web.config file for instance, and the controller on the server side could use the settings to personalize the page.

EDIT 2:

Ok. Based on the last comments I now understand that this is static configuration, i.e., it is deployment specific, and does not change based on a user on the same website for instance. Considering that, I feel this should not be part of the build process, but of deployment.

I would seriously consider using a deployment tool to customize the files based on target environment. Microsoft's own Release Management can achieve that relatively easily using the built-in workflow activities. In the release pipeline, you could pick the javascript file you want, based on any parameter you pass to the workflow.

like image 114
julealgon Avatar answered Jan 02 '23 21:01

julealgon