Visual Studio (C#): Use web.debug.config without publishing

Asked

Viewed 28 times

0

I would like to have 2 configuration files in my application c#. They would be web.config and web.debug.config.

The goal of this is that I can put some settings like database access and some appsettings according to the programmer who is programming.

That is, imagine that programmer A will connect in the database with user A and programmer B will connect in the database with user B.

Note that I am talking about connection to the database and not access permission due to x person logged into my system. It’s just so programmers don’t mess with the same database.

I tried using web.debug.config, but it only runs when I publish the application. Then this does not solve, because in production, will be only 1 connection user.

What I need is for every programmer to own their web.config.

An alternative is to put web.config as ignore in git so that everyone gets their local file. But, this is bad to manage due to other fields that need to be edited on the web.config.

In short: Is it possible to run web.debug.config when I do F5 (Debugging)? If that’s not possible, you have some other idea?

Thank you.

2 answers

0

I believe you can move the string conection to a separate file and just add that file to git ignore.

Web.Config

 <connectionStrings configSource="ConnectionStrings.config" />

Connectionstrings.config:

<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
    <add name="name" connectionString="server=(local);database=db;user Id=usr;password=pass;timeout=0"></add>
</connectionStrings>
  • Cool this model. It wasn’t my initial idea, but it was nice to know that it is possible to separate part of the web.config file. Thank you for helping @Lucas Silva.

0

Apparently you are using the . Net "Full" framework, although it is not specified in the question. In this case, it would indicate the use of the slow Cheetah package/extension.

The extension will add features to the visual studio that make it easier to use. The nuget package will allow the use of XML files that cause changes to the original configuration and is done by environment.

Extension: https://marketplace.visualstudio.com/items?itemName=vscps.SlowCheetah-XMLTransforms

Nuget package: https://www.nuget.org/packages/SlowCheetah/

By installing the above 2 libraries, VS will automatically take care of all the work. And then you can create a transformation for the Connection string.

I found this guide step by step, but despite being in English, has images of all the steps: https://www.c-sharpcorner.com/article/transform-config-using-slow-cheetah/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.