[英]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.我正在尝试动态获取 VB 项目的基本路径,因为运行项目的路径会发生变化。
Let's say that the VB Project file is in C:\\MyVBProjects\\May2016\\MyProject\\MyApp.vbproj
假设 VB 项目文件在C:\\MyVBProjects\\May2016\\MyProject\\MyApp.vbproj
I tried using Application.ExecutablePath, Assembly.GetExecutingAssembly().Location and Application.StartupPath
我尝试使用Application.ExecutablePath, Assembly.GetExecutingAssembly().Location and Application.StartupPath
The above three return C:\\MyVBProjects\\May2016\\MyProject\\bin\\Debug\\
以上三个返回C:\\MyVBProjects\\May2016\\MyProject\\bin\\Debug\\
I also tried using the following code:我还尝试使用以下代码:
Curr = Directory.GetCurrentDirectory()
Root = Directory.GetRootDirectory(Curr)
This returns just C:\\
这仅返回C:\\
Is there anyway I can get it to say C:\\MyVBProjects\\May2016\\MyProject\\
?无论如何我可以让它说C:\\MyVBProjects\\May2016\\MyProject\\
吗?
I'm currently using Visual Basic 2012 on Windows 7.我目前在 Windows 7 上使用 Visual Basic 2012。
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.您应该引用“envdte”(在程序集 -> 扩展中)并导入 envDTE。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.