I’m having an issue where visual studio is modifying my web.config for encoded values on publish, but not on build, which wouldn’t be a major issue except it’s incorrectly changing them. Specifically, I need a tab character and it’s changing to a space, but I would really prefer it not change anything on a publish, especially if it didn’t change it when running the app locally.
I am running VS 17.12.4 using .net framework 4.8.09032.
I can recreate this by doing the below…
- create new application – ASP.NET Web Application (.NET Framework) – select Web API, leave all other settings at default
- add the below to appSettings in Web.Config
<add key="TabValue1" value="	"/> <add key="TabValue2" value="	"/> <add key="LTValue1" value="<"/> <add key="LTValue2" value="<"/>
- Delete the Values controller
- Create a new controller and add the below
[HttpGet] public HttpResponseMessage Get() => Request.CreateResponse(HttpStatusCode.OK, new { TabValue1 = ConfigurationManager.AppSettings["TabValue1"], TabValue2 = ConfigurationManager.AppSettings["TabValue2"], LTValue1 = ConfigurationManager.AppSettings["LTValue1"], LTValue2 = ConfigurationManager.AppSettings["LTValue2"] });
- Create a new folder publish profile using Debug configuration
- Publish the api
- Run the api in localhost
Hitting the new endpoint on local host yields the below as expected, and the config file in the bin looks the same as the Web.config.
{ "TabValue1": "\t", "TabValue2": "\t", "LTValue1": "<", "LTValue2": "<" }
However, the web.config file in the publish directory looks like the below.
<add key="TabValue1" value=" " /> <add key="TabValue2" value=" " /> <add key="LTValue1" value="<" /> <add key="LTValue2" value="<" />