gpt4 book ai didi

c# - Visual Studio 2012 : Switch from debug to realease easily

转载 作者:行者123 更新时间:2023-12-02 04:51:34 24 4
gpt4 key购买 nike

我们正在使用大约 5 个通过网络电话连接在一起的项目。

现在,网络调用的 Uris 通过标签保存在 web.config 文件中。

<add key="ProductsAPIURL" value="http://192.168.1.4:5000" />

当我们处于 Debug模式时,我们在所有项目中更改 api 调用的 uri 以匹配本地主机端口。

将其投入生产时,我们会将它们改回来。

有没有其他方法可以轻松地从 Debug 切换到 Release 而不必每次都手动更改设置? (类似于创建一个记住所有这些设置的 visual studio 配置文件)

最佳答案

您可以使用调试和发布配置。您将拥有以下文件:

Web.config
Web.Debug.Config
Web.Release.Config

您可以在 Web.config 中定义一个连接字符串并在 Web.Release.Config 中覆盖它:

Web.config:

<connectionStrings>
<add name="MyConString" connectionString="Data Source=." />
</connectionStrings>

Web.Release.config:

<connectionStrings>
<add name="MyConString" connectionString="Data Source=different" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

或者您可以使用预处理器指令 #if

#if DEBUG
myConString = "Data Source=."
#else
myConString = "Data Source=different"
#endif

关于c# - Visual Studio 2012 : Switch from debug to realease easily,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18756698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com