Environment.CurrentDirectory is yielding unexpected results when running installed app

前端 未结 5 1938
既然无缘
既然无缘 2020-12-06 10:49

Background:

I built an installer for my app, and all my dll\'s and content files are getting correctly copied to the C:\\Program Files\\MyComp

5条回答
  •  一个人的身影
    2020-12-06 11:09

    If you want to get the path to the directory under which your executable runs, you should not rely on the Environment.CurrentDirectory, since it can be changed in a number of ways (shotrtcut settings, etc). Try one of these options instead:

    System.IO.Path.GetDirectoryName(Application.ExecutablePath);
    

    or

    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
    

提交回复
热议问题