C# Windows Get Assembly Path

Wİndows service ‘de exenin bulundugu yere bazen ulaşmada sıkıntı olabiliyor. (windows klasorunu görüyor servisler bazen) . Örnek exe klasorunde dosyaya erişimde yaşanan sıkıntı ….

string pathofService = System.IO.Path.GetDirectoryName(new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath)+@"\";
/*or*/
string pathofService = AppDomain.CurrentDomain.BaseDirectory ++@"\";

VS 2017 WINDOWS SERVICE PROJECT SETUP

  1. Right click on the setup project in your Solution Explorer.
  2. Select View > Custom Actions. (In VS2008 it might be View > Editor > Custom Actions)
  3. Right-click on the Install action in the Custom Actions tree and select ‘Add Custom Action…’
  4. In the “Select Item in Project” dialog, select Application Folder and click OK.
  5. Click OK to select “Primary output from…” option. A new node should be created.
  6. Repeat steps 4 – 5 for commit, rollback and uninstall actions.