创建C#Winform开发和生产环境 [英] Creating C# Winform Development and Production Environments

查看:344
本文介绍了创建C#Winform开发和生产环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为C#winforms项目正确创建开发和生产环境的最佳方法是什么。不幸的是,没有开发环境。而是,每次我要创建生产或开发构建时,都必须指定发布路径。另外,由于每个prod或dev构建都使用不同的连接字符串,因此我还必须进入代码并对其进行更改。

I am wondering what is the best way to properly create a Development and Production environment for my C# winforms project. The unfortunate thing is that there is no development environment. Rather, I must specify the publish path each time i wish to create either the Production or Development build. Also since each prod or dev build uses a different connection string I must then go into the code and change that as well.

编辑我想补充一点的事实是,测试人员可以从本地.exe运行该程序,该程序将查看源文件并检测是否需要进行更新。我要提到的唯一原因是因为测试人员不会在调试模式下运行代码。

EDIT Another thing i would like to add is the fact that the 'testers' so to speak will be running the program from a local .exe which will look at the source files and detect if an update needs to be made. The only reason i am mentioning this is because the testers will not be running the code in 'DEBUG' mode.

有什么想法吗?

谢谢!

推荐答案

更新

Whew,2009年肯定是很久以前了;)我将保留后代的原始答案,但是,作为 Eric J.在2012年发布的帖子的更新版本中已经声明 Slowcheetah 是解决此问题的灵活得多的方法,因为它使您可以为每个配置创建多个配置文件。

Whew, 2009 sure was a long time ago ;) I'm going to leave the original answer for posterity, but, as Eric J. already stated in an updated version of his post in 2012, Slowcheetah is a much more flexible approach to this problem as it let's you create multiple config file per configuration.

原始答案

我无法回答发布部分,因为我我不确定是否可以做到。但是,对于连接字符串部分,可以创建一个连接字符串提供程序类,如果您正在开发中,则将返回开发连接字符串,如果您正在生产中,则将返回生产连接字符串。

I can't answer for the publish part as I'm not sure it can be done. However, for the connection string part, you could make a "Connection String Provider Class" which would return the development connection string if you are in development, or the production connection string if you are in production.

我不知道您是否在配置管理器中使用调试和发布编译模式,但可以将其与预编译器指令一起使用:

I don't know if you are using Debug and Release compilation mode in the configuration manager, but it could be possible to use that with a pre-compiler directive:

public class ConnectionStringProvider
{
  public static string GetConnectionString()
  {
    #if (DEBUG)
      return DevConnectionString;
    #else
      return ProdConnectionString;
    #endif
  }
}

如果您使用的是在 VS2005设置窗格中(在项目设置中),您可以在其中设置2个连接字符串,并使用它代替恒定值。如果您使用任何.Net数据源,则可能始终使用DEV连接字符串创建对象。

If you are using the VS2005 Settings pane (in the project settings), you can set 2 connections strings in there and use that instead of a constant value. If you are using any of the .Net DataSource, you could be always using the DEV connection string to create your object.

此外,连接字符串提供程序可以使用Singleton模式,但我不确定会带来真正的好处。

Also, the connection string provider could use a Singleton pattern, but I'm not sure there would be a real benefit.

这篇关于创建C#Winform开发和生产环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆