According to an earlier question about Visual Studio configurations, there's no way to use Visual Studio's configuration manager to create different configurations for an ASP.net web site project.
根据之前关于Visual Studio配置的问题,没有办法使用Visual Studio的配置管理器为ASP.net网站项目创建不同的配置。
For normal projects, we have #if directives that switch certain server or database variables depending on whether we're debugging or in production. This doesn't work for web sites.
对于普通项目,我们有#if指令根据我们是在调试还是在生产中切换某些服务器或数据库变量。这不适用于网站。
For example, in a class (in App_Code) that defines a web site's back-end server connection, there might be a chunk of code like this which overrides production values in the web.config if you want to run a debug server on your local machine:
例如,在定义网站的后端服务器连接的类(在App_Code中)中,如果要在本地运行调试服务器,可能会有一大堆这样的代码覆盖web.config中的生产值。机:
#if DEBUGLOCAL
ServerProperties.ServerIP = "localhost";
ServerProperties.DataContextIP = "localhost";
#endif
This doesn't work, since there's no "Debug Local" configuration for the website, thus no DEBUGLOCAL defined.
这不起作用,因为网站没有“Debug Local”配置,因此没有定义DEBUGLOCAL。
Have you found a good way to work around problems like this? Besides (I hope) refactoring everything so all those references live in a class library project?
你有没有找到解决这类问题的好方法?此外(我希望)重构所有这些引用都存在于类库项目中?
ETA: Can web deployment projects help here?
ETA:Web部署项目可以在这里提供帮助吗?
2 个解决方案
#1
Perhaps a Web Deployment project that does some swapping in the web.config may be of some help? Another thought would be to have a connection string in the web.config that pulls various values from a pre-specified database that can exist in each environment to allow for easy changes to the settings without needing to touch any files.
也许在web.config中进行一些交换的Web部署项目可能会有所帮助吗?另一个想法是在web.config中有一个连接字符串,它从每个环境中可以存在的预先指定的数据库中提取各种值,以便轻松更改设置而无需触摸任何文件。
#2
Another option may be to upgrade the web site to a web application.
另一种选择可能是将网站升级为Web应用程序。
That could be a lot of work to make the transition now, but the ability to have configurations may help tip the scales if you're deciding to go with a web site or web application.
现在进行转换可能需要做很多工作,但如果您决定使用网站或Web应用程序,那么进行配置的能力可能有助于提升规模。
#1
Perhaps a Web Deployment project that does some swapping in the web.config may be of some help? Another thought would be to have a connection string in the web.config that pulls various values from a pre-specified database that can exist in each environment to allow for easy changes to the settings without needing to touch any files.
也许在web.config中进行一些交换的Web部署项目可能会有所帮助吗?另一个想法是在web.config中有一个连接字符串,它从每个环境中可以存在的预先指定的数据库中提取各种值,以便轻松更改设置而无需触摸任何文件。
#2
Another option may be to upgrade the web site to a web application.
另一种选择可能是将网站升级为Web应用程序。
That could be a lot of work to make the transition now, but the ability to have configurations may help tip the scales if you're deciding to go with a web site or web application.
现在进行转换可能需要做很多工作,但如果您决定使用网站或Web应用程序,那么进行配置的能力可能有助于提升规模。