Building a C # Winform Development and Production Environment

I am wondering what is the best way to create a dev / production environment for my C # winforms project. Unfortunately there is no development environment. Rather, I have to provide the publish path every time I want to create a Production or Development assembly. Also, since each prod or dev build uses a different connection string, I must then go into the code and change that.

EDIT One more thing I would like to add is that the "testers", so to speak, will run the program from a local .exe that will look at the original files and detect if an update needs to be done. The only reason I mention this is because testers will not run code in "DEBUG" mode.

Any ideas?

Thanks in advance!

+2


source to share


4 answers


UPDATE

Wow 2009 was sure it 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 issue as it allows you to create multiple config files for each configuration,

Original Answer

I cannot answer for posting as I am not sure if it can be done. However, for the connection string portion, you can create a "Connection Provider String Class" that will return a development connection string if you are in development, or a production connection string if you are in production.



I don't know if you are using the Debug and Release compilation mode in the configuration manager, but this could be used with the precompiler directive:

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

      

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

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

+3


source


I'm not sure what you mean by

The unfortunate thing is that there is no development environment.

However, I would point out that you can handle things like

Also, since each prod or dev build uses a different connection string I have to then go into the code and change that as well.

with conditional compilation flags. For example, you could do something like:



#if DEBUG
connString = "ABC";
#else
connString = "DEF";
#endif

      

DEBUG may not be the appropriate flag for your environment. You can define your own flags, such as PROD or DEV, and specify whether to define them for a specific build type, or from the command line if built outside of the IDE.

UPDATE

Since this answer was posted, SlowCheetah has become available. It allows you to transform XML for your app.config / web.config (and for any other XML file like NLog config files) for each build configuration. So, if you specified a QA build config, you can transform the XML for QA that installs eg. the appropriate connection string for the QA environment.

It is preferable to place configuration lines and similar in your source code.

+3


source


You can read the connection string from the config file.

Then you used the same program file in PROD and DEV, just in a different config file.

+1


source


How do I use a virtual PC to create a separate environment? This is the best practice now.

+1


source







All Articles