简体   繁体   中英

How do I get the Base Directory of my Project (The path where the .vbproj or .sln file are located)

I'm trying to get the Base path of my VB Project dynamically since the path that the project is run from will change.

Let's say that the VB Project file is in C:\\MyVBProjects\\May2016\\MyProject\\MyApp.vbproj

I tried using Application.ExecutablePath, Assembly.GetExecutingAssembly().Location and Application.StartupPath

The above three return C:\\MyVBProjects\\May2016\\MyProject\\bin\\Debug\\

I also tried using the following code:

Curr = Directory.GetCurrentDirectory()
Root = Directory.GetRootDirectory(Curr)

This returns just C:\\

Is there anyway I can get it to say C:\\MyVBProjects\\May2016\\MyProject\\ ?

I'm currently using Visual Basic 2012 on Windows 7.

Works in design time :

    Dim DTE As EnvDTE.DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE")
    Dim Prj As Project = DTE.Solution.Projects.Item(1)
    Dim PrjFile As String = Prj.FullName

You should reference "envdte" (in Assemblys -> extensions) and imports envDTE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM