?
Solved

Get project path

Posted on 2011-09-20
9
Medium Priority
?
557 Views
Last Modified: 2012-06-27
Hallo everyone,

I'm trying to get a project path from my instance project.

*******************************
Normal Visual studio

normalSolution.sln
-> normalProject1.csproj (C:\a\b\c\normalProject1.csproj)
-> normalProject2.csproj (C:\x\y\z\normalProject2.csproj)
*******************************
In my Instance project

MyNewSolution.sln (C:\a\b\c\)
-> MyNewMainProject.abc (C:\a\b\c\MyNewMainProject\MyNewMainProject.abc)
---> name1.newcsproj (C:\a\b\c\MyNewMainProject\name1\name1.newcsproj)
---> name2.newcsproj C:\x\y\z\name2\name2.newcsproj)
*******************************

How can I get these 2 path?
---> name1.newcsproj (C:\a\b\c\MyNewMainProject\name1\name1.newcsproj)
---> name2.newcsproj C:\x\y\z\name2\name2.newcsproj)

Thank you very much in advance. :)

//with this code I can get only "MyNewMainProject.abc (C:\a\b\c\MyNewMainProject\MyNewMainProject.abc)"

EnvDTE.DTE dte = (EnvDTE.DTE)this.ServiceProvider.GetService(typeof(EnvDTE.DTE));
Array a = (Array)dte.ActiveSolutionProjects;
for (int i = 0; i < a.Length; i++)
{
     project = (EnvDTE.Project)a.GetValue(i);
}

Open in new window

0
Comment
Question by:chang2008
  • 5
  • 4
9 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36566004
string path = Directory.GetParent(Path.GetDirectoryName(Application.StartupPath)).FullName

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/0ebcd39b-f2c5-45bd-a462-8ab366225980/
0
 

Author Comment

by:chang2008
ID: 36566384
From EaswaranP anwer, I've got "C:\\"
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36566433
may be this will help u

sPath = System.AppDomain.CurrentDomain.BaseDirectory;

or else

sAppPath = Environment.CurrentDirectory;

try this out!

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:chang2008
ID: 36572520
The result is

sPath = System.AppDomain.CurrentDomain.BaseDirectory;
sPath = my exe path

sAppPath = Environment.CurrentDirectory;
sAppPath = my bin\\Debug path

Unfortunately, both are not project path.
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36572540
Below code gives correct result for me.
using System;
using System.IO;
using System.Xml.Linq;
using System.Xml;
using System.Collections;

namespace TestApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            
            string path = Directory.GetParent(Path.GetDirectoryName(Environment.CurrentDirectory.ToString())).FullName;

            Console.WriteLine(path);
            Console.Read();

        }
    }
}

Open in new window

0
 

Author Comment

by:chang2008
ID: 36572914
It shows the project path of my development project not from my instance project.

My project is dealing with COM Object and DSL.
http://msdn.microsoft.com/de-de/library/microsoft.visualstudio.package.projectnode(v=vs.90).aspx
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36572947
What do you mean by Instance project?

 However run the code from your instance project to get the result. From wherever you run it will give the path where the project resides.
0
 

Author Comment

by:chang2008
ID: 36573147

I'm programming a custom project like below :
http://msdn.microsoft.com/en-us/library/aa289144(v=vs.71).aspx

When I click on start debugging, the new visual studio will start. Then I add the new solution. After that I add my custom project.

That's mean now I have 2 Visual studio starting in my computer. 1st is what I'm programming and 2nd is what I'm debugging.

from your code this one ....
string path = Directory.GetParent(Path.GetDirectoryName(Environment.CurrentDirectory.ToString())).FullName;

It show the path (of project) what I'm programming. It doesn't show the path (of custom project) what I'm debugging.

Oops! ... I'm very bad in explaining something. Sorry. :(
0
 
LVL 16

Accepted Solution

by:
Easwaran Paramasivam earned 2000 total points
ID: 36573173
Well. I was not aware of that.  I refered the link that you have provided. I observed that at point number 7 it is given as  var strProjectPath = wizard.FindSymbol("PROJECT_PATH"); whether it returns what you expect?
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question