Archana
Archana

Reputation: 75

Can I change the connectionString text in webconfig file in BeforePublish event in VS2019?

In my ASP.Net MVC Project, I have the connection string for the sql server in the webConfig file. But during development we use the test server and while publishing we change the connection string to the mainserver and then we will publish it.

Is there any way to automate this change? For example, in the Beforepublish event or should I do that in different branches?

Upvotes: 0

Views: 35

Answers (1)

Rajdeep D
Rajdeep D

Reputation: 3900

You can use environment specific web.config files and keep environment specific connection string in respective config file.

  1. In solution explorer, click on 'Show All Files'
  2. Expand Web.config files, you will see Web.Debug.config and Web.Release.config. You can add more config. For that from Build >> Configuration manager menu, go to your project and at Configuration column create a new entry by selecting <New... > from the drop down.

Show All Files, enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 1

Related Questions