This is out-of-process (in it's own) in the form of an EXE. Basically, I'm
modifying Sapient's Buildit script (cited in an MS Patterns & Practices doc
on team development) to make use of the CopyProject tool for web
applications. To do this, I need an instance of the VSProject class.
Here's some code that should illustrate what's going on.. This is just an
exerpt, but is the distilled code that I've run against multiple C#
solutions, with consistent results. Again, this runs as an exe from the
command line, but I'd imagine you could wrap it up quickly in a windows form
or something for ease of use.
So when started, the program starts VS.Net (this is straight from the source
of Sapient's BuildIt script, and works well enough to load a solution and
build it).
const string DEFAULT_VISUAL_STUDIO_PROGID = "VisualStudio.Solution";
string progID = ConfigurationSettings.AppSettings["visualStudioProgID"];
if (progID == null)
{
progID = DEFAULT_VISUAL_STUDIO_PROGID;
}
Trace.WriteLineIf(this.traceLevel.TraceVerbose, String.Format("Activating
Visual Studio.NET using progID '{0}'", progID));
Solution solution;
Type t = Type.GetTypeFromProgID(progID);
object obj = Activator.CreateInstance(t, true);
solution = (Solution) obj;
solution.Open(strSolutionPath);
Now check all Projects in the solution for the proper Kind value to cast
Project as VSProject
VSProject vsProject;
foreach (Project myProj in solution.Projects)
{
Trace.WriteLine(myProj.Kind);
if (myProj.Kind==PrjKind.prjKindVBProject)
{
Trace.WriteLine(myProj.Kind + myProj.Name+" is a VB project");
vsProject = project.Object as VSProject;
}
else if ((myProj.Kind==PrjKind.prjKindCSharpProject))
{
Trace.WriteLine(myProj.Kind + myProj.Name + " is a C# project");
vsProject = project.Object as VSProject;
}
else
{
Trace.WriteLine(myProj.Name + " Is a C++ or other project type");
}
}
Notice how the first line in the loop outputs the Kind property for the
project, then the if statements check against specific values. The problem,
I've noticed, is that the Project.Kind property is returning one of the
vsProjectKind constants, not an element fromt he PrjKind enumerator as I
would have expected.
So I guess this is what I'm confused about.. Your macro doesn't look too
different, save for the context of the Design-Time Environment. As you
mentioned, the macro would be running in the same process as the IDE, in the
context of the DTE. In the code above, I'm firing up the IDE from outside
automation, loading a solution, then trying to examine the projects within.
Thanks for helping out, and thanks for your patience -- took me a while to
get back to you.. Let me know if you have any questions, I'll be happy to
answer..
S
[quoted text, click to view] "Mike Wong (Microsoft)" <mikewong@online.microsoft.com> wrote in message
news:Xs$Hnnr3DHA.1988@cpmsftngxa07.phx.gbl...
> Hi Stephen,
>
> thanks for the reply.
>
> I was wonderinf if got a chance to test out my macro above to see if you
> get the same results? I should have also asked you if you are automating
> from out of process i.e. from another exe or in process i.e. add-in,
macro,
> etc...
>
> much appreciated,
> Mike Wong
> Microsoft Developer Support
> --------------------
> >From: "Stephen J. Shephard" <stephen@acsalaska.com>
> >References: <e3o3Ijm1DHA.2580@TK2MSFTNGP09.phx.gbl>
> <EA4IJxW2DHA.2184@cpmsftngxa07.phx.gbl>
> >Subject: Re: Project.Kind returning unexpected values
> >Date: Wed, 14 Jan 2004 18:25:36 -0900
> >Lines: 185
> >X-Priority: 3
> >X-MSMail-Priority: Normal
> >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> >Message-ID: <e9Ei#cx2DHA.536@tk2msftngp13.phx.gbl>
> >Newsgroups: microsoft.public.vsnet.enterprise.tools
> >NNTP-Posting-Host: host060.acsalaska.com 209.193.44.173
> >Path:
>
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
> phx.gbl!tk2msftngp13.phx.gbl
> >Xref: cpmsftngxa07.phx.gbl microsoft.public.vsnet.enterprise.tools:1613
> >X-Tomcat-NG: microsoft.public.vsnet.enterprise.tools
> >
> >Thanks for your help Mike, I'm sorry but I only just now caught the
> postings
> >as I was watching a different group for replies. I'll check into this
> >tomorrow (15th) and hopefully be able to give more information and answer
> >your questions.
> >Again, thanks for your help and patience.
> >
> >"Mike Wong (Microsoft)" <mikewong@online.microsoft.com> wrote in message
> >news:EA4IJxW2DHA.2184@cpmsftngxa07.phx.gbl...
> >> Hi Stephen,
> >>
> >> could you please look at my steps below to see what I might be doing
> >> differently except the fact that mine is a macro.
> >>
> >> 1. Created a web project.
> >> 2. Went to tools->macros->macros ide.
> >> 3. Created a macro like the following in module1
> >> Public Sub AnalyzeDummyWeb()
> >> Dim p As Project = DTE.Solution.Projects.Item(1)
> >> Dim prop As [Property]
> >> MsgBox(p.Kind)
> >>
> >> If (p.Kind = PrjKind.prjKindCSharpProject) Then
> >> Dim vsProj As VSProject
> >> vsProj = CType(p.Object, VSProject)
> >> MsgBox(vsProj.Project.Name)
> >> End If
> >>
> >> End Sub
> >> 4. went back to vs.net and ran the above macro.
> >> 5. It pops up with the correct project name and runs the code in the
> >> conditional.
> >>
> >> In my case, it does report back as prjKindCSharpProject. I am using
> >Visual
> >> Studio .NET 2003. What am I doing differently?
> >>
> >> thanks for any additional information.
> >>
> >> Mike Wong
> >> Microsoft Developer Support
> >> --------------------
> >> >>From: "Stephen J. Shephard" <stephen@acsalaska.com>
> >> >>Followup-To: microsoft.public.vstudio.development
> >> >>Subject: Project.Kind returning unexpected values
> >> >>Date: Thu, 8 Jan 2004 19:26:41 -0900
> >> >>Lines: 94
> >> >>X-Priority: 3
> >> >>X-MSMail-Priority: Normal
> >> >>X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> >> >>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> >> >>Message-ID: <e3o3Ijm1DHA.2580@TK2MSFTNGP09.phx.gbl>
> >> >>Newsgroups:
> >>
>
>microsoft.public.vsnet.documentation,microsoft.public.vsnet.enterprise.tool
> s
> >>
>
>,microsoft.public.vsnet.general,microsoft.public.vsnet.ide,microsoft.public