Solved

Get project path

Posted on 2011-09-20
9
543 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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