Solved

Get project path

Posted on 2011-09-20
9
545 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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