C#获取可执行文件地址

.Net Core里由于仅保留最基层的类库,编译后,一些附加类库是无法附加生成的,所以一些原来的写法不具有通用性,下面的通用性写法,适用于.Net 标准类库与.Net Core类库:

 /// <summary>
        /// 可执行文件地址
        /// </summary>
        private readonly string _locationPath = System.IO.Directory.GetCurrentDirectory();

        /// <summary>
        /// 文件版本信息
        /// </summary>
        public string ViewFileVersion
        {
            get
            {
                return string.Format("V{0}", FileVersionInfo.GetVersionInfo(_locationPath + "\\WPF.View.dll").FileVersion);
            }
        }
       
        /// <summary>
        /// 版本信息
        /// </summary>
        public string ViewVersion
        {
            get
            {                
                var assembly = Assembly.LoadFile(_locationPath + "\\WPF.View.dll");
                return string.Format("V{0}", assembly.GetName().Version);
            }
        }