Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / November 2005

Tip: Looking for answers? Try searching our database.

Custom tool interface in VS.NET 2003 questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith Dorken - 02 Dec 2003 19:08 GMT
We are trying to get one of our tool programs integrated into the build
process for a VS.NET C# project.

The tool we want to use is a parser generator which runs as a console-mode
Win32 application and reads a YACC-like grammar from an input file and
generates C# source code into an output file and error messages to its
standard output.

We want the input (*.y) file to be what the programmer edits in a text edit
window in the VS IDE, and also what is checked into the source control
system.

Ideally we want the generation of the C# output to occur at build time (that
is, when the user runs the "build" or "rebuild" menu commands for the
project, and we do not want the C# file to be under source control.

I want to emphasize that the tool does not interact with the user and does
not assist in the creation of the .y file. I mention this because most
searches for help on "custom build tools" seem to fall into this model,
programs which interact with the user to "edit" the "source" in some
graphical method.

Our current method for doing this integration is using an assembly written
as a C# project based on code found on the Web. The assembly has has a class
derived from BaseCodeGeneratorWithSite (ultimately derived from
IVsSingleFileGenerator and IObjectWithSite). When IVsSingleFileGenerator's
Generate method is called, our code uses System.Diagnostics.Process to run
the parser-generator app, and loops reading error messages from the
StandardOutput member of the Process object. The code parses the error
message to extract severity and source location information, and ultimately
calls the GeneratorError method of the IVsGeneratorProgress object which was
originally passed to Generate. The generated parser (which was written to a
temporary file) is read and returned via the rgbOutputFileContents argument
of Generate. The assembly is registered with COM and its class ID is
registered appropriately (I think) under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Generators.

This more or less does the right thing. The tool runs, the generated C# code
appears in a file, and when the assembly is built, the code is compiled and
included in the assembly.

Minor annoyances in this interface are that the tool runs when the .y file
is changed and saved, rather than when the project is built, and that the
.cs file in which the tool's output is stored is added to source control.

The main problem we are currently encountering is that, although the error
messages of the tool show up in the Task List as "build errors" and show the
correct filename and line number, double-clicking on one of these lines
opens the input (.y) file but *does not go to the line of the error*.

So we have several questions...

1 - Is this the right approach to use for this sort of tool?

2 - Is there any way to make the file management work as mentioned
("ideally...") above? Currently the .cs file is generated when the user
saves the .y file and *not* when the user builds the project, and the .cs
file is placed under source management.

3 - Is there any way that an alternative filename can be attached to the
build error that appears in the Task List? This is not a concern for this
particular tool but some other tool which supports source file inclusion
could very well report errors relating to source files other than the main
input.

4 - Is there any official documentation available on IVsSingleFileGenerator
and related interfaces and registry keys?

5 - Is there any way to generate text into the Output window of the IDE? The
parser generator produces some statistics which should not rightly be placed
in the Task List but which should be recorded somewhere the user can inspect
them, and it seems that the Output window is used in this manner by the C#
compiler.

6 - (our most immediate concern) Why does double-clicking in the Task List
not position the cursor to the correct line?
Tian Min Huang - 03 Dec 2003 19:02 GMT
Hi Eric,

Thanks for your post. I am checking this issue 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.
Mike Wong (Microsoft) - 05 Dec 2003 02:43 GMT
Hi Keith,

Thanks for the patience on this issue.  I have reproduced the issue of
double clicking on the task list item that was created via the
IVsGeneratorProgress::GeneratorError.  I need to see why it is ignoring the
line number during that process.  

Here are some answers to your other questions:

>1 - Is this the right approach to use for this sort of tool?
Yes.  Mapping one form of syntax into another is perfect for custom tools.

>2 - Is there any way to make the file management work as mentioned
>("ideally...") above? Currently the .cs file is generated when the user
>saves the .y file and *not* when the user builds the project, and the .cs
>file is placed under source management.
It would be possible to get it done as one of the pre-build steps.  We
could start everything off through a macro i.e. capturing BuildEvents or an
add-in, etc..

>3 - Is there any way that an alternative filename can be attached to the
>build error that appears in the Task List? This is not a concern for this
>particular tool but some other tool which supports source file inclusion
>could very well report errors relating to source files other than the main
>input.
Not with the IVsGeneratorProgress::GeneratorError approach.  You'll need to
go the route of IVsLaunchPad.  See question 4 for more information on this
topic.

>4 - Is there any official documentation available on IVsSingleFileGenerator
>and related interfaces and registry keys?
Yes, install the VSIP SDK 2003 from vsipdev.com under downloads.  That will
contain the documentation on IVsSingleFileGenerator and registry entries
(search on "Defining registry settings for custom tools") after installing
the SDKs.

>5 - Is there any way to generate text into the Output window of the IDE? The
>parser generator produces some statistics which should not rightly be placed
>in the Task List but which should be recorded somewhere the user can inspect
>them, and it seems that the Output window is used in this manner by the C#
>compiler.
IVsLaunchPad will provide one such approach.

>6 - (our most immediate concern) Why does double-clicking in the Task List
>not position the cursor to the correct line?
I will need to debug into this aspect.  I will let you know my status when
I get more understanding.

thanks!
Mike Wong
Microsoft Developer Support

--------------------
>From: "Keith Dorken" <kadorken@nospamthinkage.ca>
>Subject: Custom tool interface in VS.NET 2003 questions
[quoted text clipped - 87 lines]
>6 - (our most immediate concern) Why does double-clicking in the Task List
>not position the cursor to the correct line?
Mike Wong (Microsoft) - 05 Dec 2003 08:54 GMT
Hi Keith,

this is followup for the below message.

>>6 - (our most immediate concern) Why does double-clicking in the Task List
>>not position the cursor to the correct line?
>I will need to debug into this aspect.  I will let you know my status when
>I get more understanding.

I debugged into this tonight and found that the IVsGeneratorProgress that
is passed into the Generate method uses a generic task provider (some
internal build manager).  now, the generic task provider has
IVsTaskItem::NavigateTo just opens the file as you have noted already.  it
does not do anything with navigating to a line and column.  That is now
verified -  there is no code in the generic implementation of NavigateTo
that does anything with the line and column.  In short, the
IVsGeneratorProgress passed into the Generate is really out of your
control.  Since it uses a generic task provider i.e. the IVsTaskItem does
nothing more than opens the document one workaround could be to register
our own task provider which would implement our own IVsTaskItem::NavigateTo
method where we could use the line and column info.  That would be a
sizable work item for us to try because we would need to define some of
these items in the managed world.  The page I mentioned below
http://vsipdev.com where you can download the VSIP SDK.  That is primarily
C++ based.  There is a beta that is mentioned on the page as well that
talks about managed support but it is not in the release stage yet.  I
can't comment on the release of it.  More information can be found in the
VSIP SDK docs that talk about IVsTaskList::RegisterTaskProvider,
IVsTaskProvider, etc.  I have not tried this so there could be things like
the COM object lifetime of your generator that come into play so it might
have to move to a package or add-in scenario...

What are your thoughts?

thanks!
Mike Wong
Microsoft Developer Support
--------------------
>X-Tomcat-ID: 74601438
>References: <#j5z8eQuDHA.2448@TK2MSFTNGP12.phx.gbl>
[quoted text clipped - 168 lines]
>>6 - (our most immediate concern) Why does double-clicking in the Task List
>>not position the cursor to the correct line?
Keith Dorken - 05 Dec 2003 15:27 GMT
Thanks for the detailed information; we'll investigate the SDK documentation
and see where we go.
Keith Dorken - 09 Dec 2003 19:36 GMT
UPDATE on our progress (with some more questions)
We downloaded the latest VSIP SDK 2003 and found that it contained no
further documentation on IVsSingleFileGenerator. The original web site where
we found the code template we first used implied that this was no longer
part of the SDK, and the absence of any mention of it in the documentation
would tend to confirm this.

We are wondering if this was correct, and if there was a recommended
replacement?

Bridging the .NET environment and the COM objects in VS is not really a
problem, except that only a few interfaces already exist in referenceable
assemblies, so we have to convert the IDL declarations for some of the
interfaces into C# interface declarations with appropriate attributes. The
.NET environment then manages all the marshalling and lifetime issues.

However we did determine that using
IVsOutputWindowPane::OutputTaskItemString might be the best way to record
the parser generator errors, that is, instead of calling the
IVsGeneratorProgress methods with the errors, we would call
OutputTaskItemString directly.

This appeared to have several advantages:
1- Simplicity; this seemed much easier than defining our own
TaskItemProvider and all associated baggage.
2- Errors are also placed in the Output window, and statistical messages
from the tool could be placed there as well without generating Task List
entries by calling IVsOutputWindowPane::OutputString
3- Errors would be better identified than the "Custon Tool Error" prefix
that IVsGeneratorProgress adds to the message text

We wanted to place the messages in the Build output pane, which has a
well-known uuid (1BD8A850-02D1-11d1-bee7-00a0c913d1f8) identifying it, but
in order to access *any* of the panes, we first have to get the OutputWindow
service, but we find that calls to IOleServiceProvider::QueryService with
the appropriate service uuid (which happens to be the same as
533FAD11-FE7F-41EE-A381-8B67792CD692, the IID for IVsOutputWindow) fail to
return an object. Unfortunately IOleServiceProvider does not provide any way
to enumerate the entire service list (unless that is itself a service one
can request), so we cannot even determine what *is* provided.

Could we be querying incorrectly for this service, or could the site
supplied to our extension object's IObjectWithSite::SetSite method be some
sort of proxy site that only supplies a subset of all the services that
should be available to VS extensions ?

We don't suppose that we should be so lucky that the VSIP SDK should contain
debug symbols for VS (particularly csproj.dll)? Are the debug symbols
available elsewhere?

Thanks in advance, Keith

> Hi Keith,
>
[quoted text clipped - 217 lines]
> >>6 - (our most immediate concern) Why does double-clicking in the Task List
> >>not position the cursor to the correct line?
Mike Wong (Microsoft) - 10 Dec 2003 23:56 GMT
Hi Keith,

sorry about that, you are correct, it got taken out of the release version
of the docs.  The story on IVsSingleFileGenerator was that it was really
never meant to be public so they made it private for 2003.  Since it was
exposed in a MSDN article (very clear explanation), developers started to
use it.  When they made it private for 2003, it blocked customer migration
so one of the product group devs redefined it in a class library available
on gotdotnet.  My whole point is that there is no migration story for the
interface since it wasn't meant to be public in the first place.

>Could we be querying incorrectly for this service, or could the site
>supplied to our extension object's IObjectWithSite::SetSite method be some
>sort of proxy site that only supplies a subset of all the services that
>should be available to VS extensions ?

Try the following code instead (reference the envdte dll)
using EnvDTE;
..//guid = 533FAD11...
                       ProjectItem obj = (ProjectItem)
GetService(typeof(ProjectItem));
                       Window win =
obj.DTE.Windows.Item(Constants.vsWindowKindOutput);
                       OutputWindow ow = (OutputWindow) win.Object;
                       OutputWindowPane owp = ow.OutputWindowPanes.Item(1);
                       owp.OutputString("Check");
                       IOleServiceProvider serviceProvider =
(IOleServiceProvider) obj.DTE;
                       IntPtr pUnk;
                       int hr = serviceProvider.QueryService(ref guid, ref
guid, out pUnk);

While working on the code, it dawned on me that you could just use the
OutputWindowPane methods to put items into the task list and outputpane.  
Check out the methods OutputTaskItemString for the owp variable above.  I
do the QueryService off the IOleServiceProvider on the DTE object instead
to show how to get to the various services described in the environment SDK.

>We don't suppose that we should be so lucky that the VSIP SDK should contain
>debug symbols for VS (particularly csproj.dll)? Are the debug symbols
>available elsewhere?
Unfortunately no, but you could set your symbol server to the public http
symbol store to see if it pulls it down.  We might have public symbols
available.
The following article has more information
http://support.microsoft.com/default.aspx?scid=kb;en-us;319037

i.e.
symsrv*symsrv.dll*c:\localcache*http://msdl.microsoft.com/download/symbols

I hope that helps.

thanks!
Mike Wong
Microsoft Developer Support

--------------------
>From: "Keith Dorken" <kadorken@nospamthinkage.ca>
>References: <#j5z8eQuDHA.2448@TK2MSFTNGP12.phx.gbl>
<t8h5KmtuDHA.2520@cpmsftngxa07.phx.gbl>
<VVsHd1wuDHA.3088@cpmsftngxa07.phx.gbl>
>Subject: Re: Custom tool interface in VS.NET 2003 questions
>Date: Tue, 9 Dec 2003 14:36:01 -0500
[quoted text clipped - 7 lines]
>NNTP-Posting-Host: cougar.thoughts.thinkage.ca 192.102.11.6
>Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP09.phx.gbl
>Xref: cpmsftngxa07.phx.gbl microsoft.public.vsnet.ide:9655
>X-Tomcat-NG: microsoft.public.vsnet.ide
[quoted text clipped - 300 lines]
>List
>> >>not position the cursor to the correct line?
Tia - 20 Nov 2005 15:51 GMT
START YOUR OWN E-MAIL BUSINESS TODAY and TAKE ADVANTAGE OF THE FOLLOWING:

1.ALL CUSTOMERS PAY YOU IN CASH!!!
2. TOP PART-TIME OWNERS HAVE EARNED $5,000+ IN ONE MONTH!
3. TOP FULL-TIME OWNERS HAVE EARNED $10,000+ IN ONE MONTH!
4. YOU WILL SELL A PRODUCT WHICH COSTS NOTHING TO PRODUCE!
5. YOUR MAIN OVERHEAD IS YOUR TIME!
6. YOUR START UP COSTS ARE LESS THAN $25
7. YOU HAVE MORE THAN 40 MILLION POTENTIAL CUSTOMERS

For additional information please E-mail me at  saita@dodo.com.au
=====================================================

New Software that finds leads for YOU for F.R.E.E.!!!!!
http://www.contactthem.com/cgi-bin/at.cgi?a=316161

---
MAF Anti-Spam ID: 20051113184547I1n0UmZ7

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.