all groups > visual studio .net enterprise tools > january 2004 >
You're in the

visual studio .net enterprise tools

group:

Project.Kind returning unexpected values


Project.Kind returning unexpected values Stephen J. Shephard
1/8/2004 7:26:41 PM
visual studio .net enterprise tools: This concerns Visual Studio Automation and Extensibility, specifically the
DesignTimeEnvironment object and its child collections, classes, etc.

Documentation for the VSProject object shows the following VB example:

Dim aProject As Project
Dim aVSProject As VSProject

aProject = DTE.Solution.Projects.Item(1)

If (aProject.Kind = PrjKind.prjKindVBProject) Or (aProject.Kind =
PrjKind.prjKindCSharpProject) Then
aVSProject = CType(DTE.Solution.Projects.Item(1).Object, VSProject)

When I try to do something similar (in C# by the way), these tests fail.

Essentially, I'm opening a C# Web App solution, then examining the Kind
property of the only project in the solution.
Here's some sample code and results (if the first five lines look familiar
it's because they're from the BuildIt script from Sapient)..
Project prjProject;

Type t = Type.GetTypeFromProgID(progID);

object obj = Activator.CreateInstance(t, true);

solution = (Solution) obj;

solution.Open(SolutionDetail.Path);

prjProject = solution.Projects.Item(1);

Trace.WriteLine("C# PRoj: " + PrjKind.prjKindCSharpProject);

Trace.WriteLine("MyProj: " + prjProject.Kind);

Trace.WriteLine("MyProjEx: " + solution.Projects.Item(1).Kind);

Trace.WriteLine("Projects:" + solution.Projects.Kind);

if (prjProject.Kind == PrjKind.prjKindCSharpProject || prjProject.Kind ==
PrjKind.prjKindVBProject)

The condition in the last statement fails, even though this solution is all
about C#. Further, I encounter an error when I try to cast the
Project.Object object into a VSProject variable.

The values of the Trace.WriteLine statements are as follows:
C# PRoj: {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
MyProj: {67294A52-A4F0-11D2-AA88-00C04F688DDE}
MyProjEx: {67294A52-A4F0-11D2-AA88-00C04F688DDE}
Projects:{96410B9F-3542-4A14-877F-BC7227B51D3B}

As you can see, the value of the PrjKind enumerator for C# projects is
different than what the project object I'm working with reports. When I
looked up the 6729 value on MSDN, I'm given the following information:

vsProjectKind Constants
Represents pre-defined kinds of projects. Each project kind defines
different constants or values for the results of Project.Kind.
vsProjectKindMisc {66A2671D-8FB5-11D2-AA7E-00C04F688DDE} A
miscellaneous files project.
vsProjectKindSolutionItems {66A26720-8FB5-11D2-AA7E-00C04F688DDE} A
solution items project.
vsProjectKindUnmodeled {67294A52-A4F0-11D2-AA88-00C04F688DDE} An
unmodeled project.


This information is different than what one sees for the PrjKind enumerator
values:

Indicates the type of the Project object.

Constant Value Description
prjKindVBProject {F184B08F-C81C-45F6-A57F-5ABD9991F28F} Visual Basic
Projects/Project automation object kind
prjKindCSharpProject {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Visual C#
Projects/Project automation object kind
prjKindVBAProject {13B7A3EE-4614-11D3-9BC7-00C04F79DE25} Macro
Projects/Project automation object kind


So you can see that the project I've opened is reporting a Kind value of
'Unmodeled', and nothing from the PrjKind enumerator. The VB script example
seemed to imply that I'd be seeing values from the PrjKind enumerator
returned. Why would I get the value I'm getting back from querying the
Project.Kind attribute and not enumerator values? My goal is to open the
project, cast it as a VSProject and then programmatically run the
CopyProject statement. I can't even get past the casting because clearly the
Kind isn't compatible.

Hope someone can help!

RE: Project.Kind returning unexpected values timhuang NO[at]SPAM online.microsoft.com
1/9/2004 1:12:21 PM
Hello Stephen,

Thanks for your post. As I understand, the problem you are facing is that
the Project.Kind returns PrjKind enum values for VB .NET, while it returns
vsProjectKind for C#. Please correct me if there is any misunderstanding.

Does the problem only occurs to a C# Web app or to all other C# projects
like WinForm?

In the meantime, I am checking it on my side, and will update you with my
findings.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
RE: Project.Kind returning unexpected values johnei NO[at]SPAM online.microsoft.com (
1/12/2004 10:41:18 PM
Hi, Stephen

I've created an escalation with the IDE team to track your issue. They
should respond to you in this thread, hopefully on Tuesday.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
RE: Project.Kind returning unexpected values mikewong NO[at]SPAM online.microsoft.com
1/13/2004 12:29:16 AM
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
--------------------
[quoted text, click to view]
microsoft.public.vsnet.documentation,microsoft.public.vsnet.enterprise.tools
,microsoft.public.vsnet.general,microsoft.public.vsnet.ide,microsoft.public.
vstudio.development,microsoft.public.vstudio.general
[quoted text, click to view]
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
[quoted text, click to view]
microsoft.public.vsnet.general:15748 microsoft.public.vsnet.ide:10173
microsoft.public.vstudio.development:4056
microsoft.public.vstudio.general:5104
microsoft.public.vsnet.documentation:951
[quoted text, click to view]

Mike Wong
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
(c) 2002 Microsoft Corporation. All rights reserved.
Re: Project.Kind returning unexpected values Stephen J. Shephard
1/14/2004 6:25:36 PM
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.

[quoted text, click to view]

Re: Project.Kind returning unexpected values mikewong NO[at]SPAM online.microsoft.com
1/19/2004 6:27:07 PM
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
--------------------
[quoted text, click to view]
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!tk2msftngp13.phx.gbl
[quoted text, click to view]
Re: Project.Kind returning unexpected values Stephen J. Shephard
1/20/2004 4:55:22 PM
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]

Re: Project.Kind returning unexpected values mikewong NO[at]SPAM online.microsoft.com
1/21/2004 7:37:55 PM
Hi Stephen,

I converted my macro into a small console application and I still can't
quite repro :-(

using EnvDTE;
using VSLangProj;
using System.Runtime.InteropServices;
const string DEFAULT_VISUAL_STUDIO_PROGID = "VisualStudio.Solution";
string progID = DEFAULT_VISUAL_STUDIO_PROGID;


Solution solution;

Type t = Type.GetTypeFromProgID(progID);
object obj = Activator.CreateInstance(t, true);

solution = (EnvDTE.Solution) obj;
obj = null;

//for debugging purposes
solution.DTE.MainWindow.Activate();

solution.Open(@"C:\Documents and Settings\mikewong\My Documents\Visual
Studio Projects\WebApplication5\WebApplication5.sln");

foreach (Project myProj in solution.Projects)
{
if (myProj.Kind == PrjKind.prjKindCSharpProject)
{
Console.WriteLine("{0}", myProj.FullName);
VSProject vsProject;
vsProject = (VSProject) myProj.Object;
Console.WriteLine(vsProject.Project.FullName);
}
}

Console.ReadLine();
solution.DTE.Quit();
solution = null;

The only difference that I can think of is the solution that you are
opening in the solution.open. Are they ASP.NET applications contained in
the solution? Could you cut and paste the above into a simple console app
and try it out. Note, I make the mainwindow visible just so I can see what
is happening.

You can also send me your phone number and the best time when you can work
on this to my email at mikewong@microsoft.com.

much appreciated,
mike
--------------------
[quoted text, click to view]
<EA4IJxW2DHA.2184@cpmsftngxa07.phx.gbl>
<e9Ei#cx2DHA.536@tk2msftngp13.phx.gbl>
<Xs$Hnnr3DHA.1988@cpmsftngxa07.phx.gbl>
[quoted text, click to view]
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!TK2MSFTNGP12.phx.gbl
[quoted text, click to view]
Re: Project.Kind returning unexpected values Sergei Sidorenko
3/15/2004 12:46:10 PM
AddThis Social Bookmark Button