簡體   English   中英

如何獲取我的項目的基本目錄(.vbproj 或 .sln 文件所在的路徑)

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

我正在嘗試動態獲取 VB 項目的基本路徑,因為運行項目的路徑會發生變化。

假設 VB 項目文件在C:\\MyVBProjects\\May2016\\MyProject\\MyApp.vbproj

我嘗試使用Application.ExecutablePath, Assembly.GetExecutingAssembly().Location and Application.StartupPath

以上三個返回C:\\MyVBProjects\\May2016\\MyProject\\bin\\Debug\\

我還嘗試使用以下代碼:

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

這僅返回C:\\

無論如何我可以讓它說C:\\MyVBProjects\\May2016\\MyProject\\嗎?

我目前在 Windows 7 上使用 Visual Basic 2012。

在設計時工作:

    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

您應該引用“envdte”(在程序集 -> 擴展中)並導入 envDTE。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM