简体   繁体   English

如何获取我的项目的基本目录(.vbproj 或 .sln 文件所在的路径)

[英]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.

相关问题 如何在WinForm应用程序项目中获取目录的路径 - How do I get path of the Directory inside my WinForm app project 是否可以将ReferencePath信息从.vbproj.user(或.csproj.user)文件移动到相应的项目文件中? - Can I move ReferencePath information from a .vbproj.user (or .csproj.user) file into the corresponding project file? 当源文件路径更改时,如何保持与项目的数据库连接? - How do I retain database connectivity, with my project, when the source file path changes? 在解决方案中添加新图像时,是否需要签入 TFS 中的 vbproj 文件? - Do I need to check in vbproj file in TFS when I add a new image in the solution? 如何获取没有扩展名/目录的启动文件的文件名? - How do I get the filename of my launched file without extension / directory? 在没有Visual Studio的情况下编译.vbproj或.csproj项目文件 - Compiling a .vbproj or .csproj project file without Visual Studio 如何获取.NET应用程序的路径(而不是启动应用程序的应用程序的路径) - How do I get my .NET application's path (not the path of the application that started my application) 如何获得用于启动程序的关联文件的路径? - How do I get the path to the associated file used to launch a program? 在运行程序时如何更改程序的目录路径 - How do I change the directory path of my program whilst its running 打开vbproj和sln文件会导致Visual Studio打开 - Opening vbproj and sln files leads to visual studio open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM