How to overwrite a web.config file with custom content in ASP.NET Core?

238 Views Asked by At

I'm trying to extend my web.config file with custom server configuration that is necessary for IIS. But I'm not sure how to do this as there is already a web.config file auto-generated at publish time. So I need to merge my custom config into this file.

I already tried to transform the web.config file but it just could not get it working. Even if it did I would have to create for example a web.Debug.config and web.Release.config with the same content.

1

There are 1 best solutions below

0
Gabriel Weidmann On

After a lot of trial and error we found out that the solution is really easy (but for some reason we have not found a single helpful internet source that told us this thing):

The web.config files just get merged at publish time!

So I just:

  1. Added a custom web.config file
  2. with Build Action: Content and Copy to Output Directory: Copy if newer to be able to use the custom config at debug time

And now on publish I get a single web.config with both the auto generated and custom settings.