-3

In a Windows Forms C# project, I have a URL to an SSRS report and the URL depends on development/test/production environment:

  • \\dev\path\to\report
  • \\test\path\to\report
  • \\prod\path\to\report

I was wondering if the URL can be not hard coded in the source code?

More generally, if there is a string that depends on development/test/production, how can I not hard code it in source code?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

1

I don't know if this would be helpful in your situation, but you can also define configurations in your Build Properties and set conditional compilation symbols based on the specific runtime context.

conditional compilation symbols

So if you have dev, test and prod defined with different symbols...

configs

You can leverage that to do something like this:

[TestClass]
public class SandboxManager
{
    public static SemaphoreSlim UIClosedAwaiter = new SemaphoreSlim(1, 1);
    public static SemaphoreSlim SS_Boot = new SemaphoreSlim(0, 1);
    [AssemblyInitialize]
    public static async Task BootUnitTest(TestContext context)
    {
        ResourceInfo.UTRoot = @"D:\Github\xamarin-21\sasquatch-net-standard-21\sasquatch-net-standard";            
        var dir = Path.Combine(ResourceInfo.UTRoot, "Test", "Logs", $"{DateTime.Now:yyyy-MM-dd}");
        Directory.CreateDirectory(dir);
        TestBase.LogFile = Path.Combine(dir, "log.txt");
        if(File.Exists(TestBase.LogFile)) File.Delete(TestBase.LogFile);
#if SBX_SQFA
        UIClosedAwaiter.Wait(0);
        SQInstance.RunContext = RunContext.UnitTestFullUI;
        MainActivitySandbox.Boot();
        await SS_Boot.WaitAsync();
        await onBootSQFA();
#elif SBX_UI_LITE
        UIClosedAwaiter.Wait(0);
        SQInstance.RunContext = RunContext.UnitTestLiteUI;
        AppWOUISandbox.Boot();
        UIControlSandbox.Boot();
        await SS_Boot.WaitAsync();
#elif SBX_MOCK_AI
        SQInstance.RunContext = RunContext.UnitTestLiteInstance;
        AppWOUISandbox.Boot();
#else
        SQInstance.RunContext = RunContext.UnitTestPrimitive;
#endif
        SS_Boot.EnsureRelease();
        await Task.Delay(100);
    }
IVSoftware
  • 5,732
  • 2
  • 12
  • 23