Solved

Get project path

Posted on 2011-09-20
9
536 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now