Answered by:
Different strings based on publish profile

Question
-
User-1416459073 posted
Under Visual Studio 2010 you can publish your asp.net web application to another server. Is it possible to publish different versions of a string based on where you are publishing your project.
So for example. When I run the project locally on my system, I have a folder structure of c:\myapp\saved_files. But when I publish to our dev server, that folder structure changes to w:\some_folder\some_app\saved_files.
Currently in my project I constantly have to comment/un-comment a string that contains the appropriate folder information of the system I'm working on. I'm wondering if there is a way to automate this.
I'm thinking something like :
#ifndef publish_profile_dev
string folder = "w:\some_folder\some_app\saved_files";#ifndef publish_profile_local
string folder = "c:\myapp\saved_files";Wednesday, November 6, 2013 2:06 PM
Answers
-
User-837620913 posted
You can create Web Deploy parameters using XML in your project. See this blog post for an example: http://sedodream.com/2013/03/02/MSDeployHowToUpdateAppSettingsOnPublishBasedOnThePublishProfile.aspx
Or you could specify different build configurations and name your own (for example, DeployToDev and DeployToProd) and use web.config transforms: http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/web-config-transformations
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 7, 2013 5:52 AM
All replies
-
User-837620913 posted
You can create Web Deploy parameters using XML in your project. See this blog post for an example: http://sedodream.com/2013/03/02/MSDeployHowToUpdateAppSettingsOnPublishBasedOnThePublishProfile.aspx
Or you could specify different build configurations and name your own (for example, DeployToDev and DeployToProd) and use web.config transforms: http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/web-config-transformations
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, November 7, 2013 5:52 AM -
User1079421601 posted
Add key in web.config file for different server. I think its bes solution.
<appSettings> <add key="folder" value="w:\some_folder\some_app\saved_files"/> </appSettings>
//Reading appsetting value
string folderLocation = ConfigurationManager.AppSettings["folder"];Reference:
Thursday, November 7, 2013 6:10 AM -
User-1416459073 posted
I'm currently running on VS 2010, so I had to install a service pack to get an updated version of the deployment tool.
That way I was able to use web.config transformations based on my publishing profile.
A simple right click on the pubxml file and "add config transform" was what I needed.
Then I just configured the new web.config file for that profile.
Works like a charm. Thanks.
Thursday, November 7, 2013 2:21 PM