如何将 web.config 添加到 owin 自托管网站 api?

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

我实际上刚刚创建了一个 NServiceBus 自托管端点,并通过添加 Microsoft.AspNet.WebApi.OwinSelfHost nuget 包引导了 owin 自托管 Web api 2。一切正常,运行 正常,我可以访问我添加的控制器端点,但是包没有添加像 web.config.

这样的正常项目

我希望有正常的 web.config 可用,我还可以添加不同的构建配置(转换文件,如 web.debug.configweb.release.config 等)。

如何将其添加到我的项目中?

我尝试只添加文件,但 ConfigurationManager 没有读取它。

web.config 用于托管服务器上的 asp.net Web 应用程序。由于您使用的是自托管服务器,因此 web.config 不适用。您需要 app.config 来解析为具有 .config 文件扩展名的可执行文件名称。

app.config添加到项目中,ConfigurationManager应该可以读取它。

更新:

有人指出 app.config

也需要相同的配置转换

以下 VS 工具填补了 web.config 转换之间的空白。

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.

link 包括有关如何在应用配置转换时使用它的分步说明。