Better way to get the base directory?

前端 未结 9 1817
旧巷少年郎
旧巷少年郎 2020-12-25 13:59

I have this code to load a config file and read all the values and it works fine when running the application but of course fails on team city because the appdomain\'s base

9条回答
  •  天命终不由人
    2020-12-25 14:18

    I like to make my classes configurable - for example they get the folder name as a parameter in their constructor. This makes it possible to test with different config files.

    In test code we use:

    TestContext.TestDeploymentDir
    

    This is the testrun folder, where all assemblies for a test run are copied into, together with the test deployment items. We 'deploy' our unit test config files to the test run folder - this can be specified in the testrunconfig dialog in visual studio.

    For our production code we pass

    Assembly.GetExecutingAssembly().Location
    

    to the constructor, which works for us.

提交回复
热议问题