Smartkid's binary life

博客园 首页 联系 订阅 管理
The unit test in Visual Studio has a bug:
AppDomain.CurrentDomain.BaseDirectory always returns the installtion directory of the visual studio 2008 instead of the 'Out' directory.

So if your code have to access data files deployed to the 'Out' directory using relative path, error occurs.

A workaround is:

        public static GetApplicationBaseDirectory {
            
if (AppDomain.CurrentDomain.FriendlyName.StartsWith("UnitTestAdapterDomain_")) {
                
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            }

                
return AppDomain.CurrentDomain.BaseDirectory;
        }


posted on 2008-06-29 02:53  Smartkid  阅读(791)  评论(0编辑  收藏  举报