Solved

Get project path

Posted on 2011-09-20
9
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decadeā€¦

732 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