views:

552

answers:

4

Hello,

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.

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.

Any ideas?

Thanks in advance!

+1  A: 

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 must then go into the code and change that as well.

with conditional compilation flags. For example you could so 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 particular build type, or from the command line if building outside of the IDE.

Eric J.
+1  A: 

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
  }
}

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.

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

Fred
Thanks for the reply Fred. If you read my edit you can see that the people testing will not be testing from the debug environment. This brings up another question though... Can i specify publishes as debug or not?
Well, if they are not running the debug code, you could have a flag in the config file. But, in that case, you could just change the connection string's server too... I don't think that what you're searching for is built in Visual Studio, I could be wrong though.
Fred
If you look at Eric's post, he tells you that you can create more than the 2 compile preset (debug and release), you could just create a "Test" compile setup and use this one on the testing phase.
Fred
I guessed i missed that part. Can you link or tell me how to specify declaration when building? If you can, you have the answer check mark:)
Well ... you can have a look at this : http://msdn.microsoft.com/en-us/library/t1hy4dhz%28VS.80%29.aspx
Fred
A: 

You could read the connection string from a configuration file.

You would then use the same program file in PROD and DEV, just a different configuration file.

Shiraz Bhaiji
A: 

What about using Virtual PC to create a separate environment ? That's now a best-practice.

Rebol Tutorial
Unfortunately i am stuck without a virtual environment to tailor to my needs