Sinaesthetic
Sinaesthetic

Reputation: 12211

How do I add a web.config to an owin self-hosted web api?

I actually just created an NServiceBus self-hosted endpoint and bootstrapped owin self-hosted web api 2 by adding the Microsoft.AspNet.WebApi.OwinSelfHost nuget package. It's all up and running fine and I can hit the controller endpoints that I added, but the package didn't add the normal items like the web.config.

I'd like to have the normal web.config available to where I can also add in different build configurations (the transform files like web.debug.config, web.release.config, etc).

How do I add this into my project?

I tried just adding the file, but ConfigurationManager doesn't read it.

Upvotes: 4

Views: 2624

Answers (1)

Nkosi
Nkosi

Reputation: 247323

web.config is used for asp.net web application on a hosted server. As you are using a self-hosted server then web.config is no applicable. You would need app.config which would resolve to the executable name with the .config file extension.

Add app.config to the project and ConfigurationManager should be able to read it.

UPDATE:

It was indicated that the same config transformation was also needed for app.config

The following VS tool fills in the gap left between web.config transformations.

Configuration Transform

Automatically transform app.config or any other config during build process. Once the transformation is set, it will run on other build machines without the extension.

The link includes step by step instructions on how to use it in applying configuration transformations.

Upvotes: 6

Related Questions