Reputation: 39068
I run VS2010 Web Developer and I set a javascript variable to one value for testing. When I publish my work, I that variable should be another value to affect the final behavior. So, in the rumpa.js file i have the following.
$(document).ready(function () {
var iable = "test value";
...}
However, just before I execute publish, I manually edit the line so it looks as follows.
$(document).ready(function () {
var iable = "publish value";
...}
It works great, except I often forget to change the iable
to "publish value"
until an unhappy customer calls. That is not optimal development technique.
Can I somehow make VS change my source code so I won't have to?
Upvotes: 2
Views: 520
Reputation: 343
The link referenced in Rob Angelier's answer isn't working for me. Since I was looking for the same issue today, I found you can use #DEBUG:
#if DEBUG
var iable = "test value";
#else
var iable = "publish value";
#endif
However I sometimes need to publish a debug build to the server which this method does not allow for. So you can check for the server name:
var iable;
if (window.location.hostname=="localhost")
{
var iable = "test value";
} else
{
var iable = "publish value";
}
Or in Angular I use a service as:
(function () {
"use strict";
angular
.module("common.services", ["ngResource"])
.constant("appSettings",
{
commonsetting: false,
});
if (window.location.hostname=="localhost")
{
// local dev settings
angular
.module("common.services", ["ngResource"])
.constant("appSettings",
{
iable = "test value";
});
} else
{
// remote settings
angular
.module("common.services", ["ngResource"])
.constant("appSettings",
{
var iable = "publish value";
});
}
}());
Hopefully this will save someone some time.
Upvotes: 1
Reputation: 2333
You could use config transformation files. This way you can have different settings for each publish profile. More info can be found here: http://blog.hmobius.com/post/2010/02/17/ASPNET-40-Part-4-Config-Transformation-Files.aspx
Upvotes: 0