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 / Extensibility / January 2006

Tip: Looking for answers? Try searching our database.

[VS2005] Execute post-build action

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johan Nilsson - 11 Jan 2006 08:09 GMT
Hi,

is it possible to execute a VC post-build action using automation (i.e.
macros), and have the output go to the build output window?

Or, perhaps as a more general question, executing an external program and
displaying the output in e.g. the Output window?

// Johan
"Gary Chang[MSFT]" - 11 Jan 2006 10:06 GMT
Hi Johan,

>Or, perhaps as a more general question, executing
>an external program and displaying the output in
>e.g. the Output window?

I suggest you can add that external program as the VS2005 IDE's external
tool(Tools\External Tools...), and check the "Use Output window" option
when you add it in the External Tools... dialog. Then use the following
macro function to execute it:

'Assumed the target external tool is the third external tools listed in the
Tools menu
DTE.ExecuteCommand ("Tools.ExternalCommand3")

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
Johan Nilsson - 11 Jan 2006 10:12 GMT
Gary,

> Hi Johan,

And, as for the first part of my question?

>> Or, perhaps as a more general question, executing
>> an external program and displaying the output in
[quoted text clipped - 8 lines]
> in the Tools menu
> DTE.ExecuteCommand ("Tools.ExternalCommand3")

Thanks for the suggestion. However I'd like to get rid of the dependency of
having a specific external tool defined in the IDE.

// Johan
"Ed Dore [MSFT]" - 11 Jan 2006 23:04 GMT
Hi Johan,

There is no way to cause the build events (like PostBuildEvents) to fire
outside a project build operation. The only way to do this would be to
exclude all tools except the tool you wanted to run, and then do a rebuild.
The problem with this though is that all the outputs of the previous build
would wind up be deleted.

To get access to the actual VCPostBuildEventTool object for a VC project,
you have use the IVCCollection interface. Below is a quick macro that will
dump the various VCPostBuildEventTool properties to your output window. I
cobbled that together before realizing there's no way to actually execute
the tool programatically.

I don't have a solution for launching that VCPostBuildEvent.CommandLine
from a macro either. If you are in-process to devenv.exe, (from an addin or
VSIP package) you could utilize the IVsLaunchPad service documented in the
Visual Studio SDK. Like IDesignerHost, you can't actually get at this
interface out-of-process.

If you have an addin, you can convert the DTE object to a COM
IServiceProvider interface and call QueryService for the SVsLaunchPad
service to retrieve an IVsLaunchPad interface. You could then use the
ToolPath and CommandLine properties of the VCPostBuildEvent object to run
the command(s) listed in the project settings.

Public Module Module1

   Function GetMiscDumpPane() As OutputWindowPane
       Dim ow As OutputWindow =
DTE.Windows.Item(Constants.vsWindowKindOutput).Object
       Dim pane As OutputWindowPane
       Try
           pane = ow.OutputWindowPanes.Item("MiscDumpPane")
       Catch ex As Exception
           pane = ow.OutputWindowPanes.Add("MiscDumpPane")
       End Try
       Return pane
   End Function

   Sub LaunchPostBuild()
       Dim pane As OutputWindowPane = GetMiscDumpPane()
       Dim proj As Project = DTE.Solution.Projects.Item(1)
       Dim vcproj As VCProject = proj.Object
       Dim configName As String =
proj.ConfigurationManager.ActiveConfiguration.ConfigurationName
       Dim projConfigs As IVCCollection = vcproj.Configurations
       Dim projConfig As VCConfiguration = projConfigs.Item(configName)

       Dim tools As IVCCollection = projConfig.Tools
       Dim tool As VCPostBuildEventTool =
tools.Item("VCPostBuildEventTool")

       pane.OutputString("ToolName:    " & tool.toolName & vbCr)
       pane.OutputString("ToolKind:    " & tool.ToolKind & vbCr)
       pane.OutputString("Description: " & tool.Description & vbCr)
       pane.OutputString("ToolPath:    " & tool.ToolPath & vbCr)
       pane.OutputString("CommandLine: " & tool.CommandLine & vbCr)

       'For Each obj As Object In tools
       '    pane.OutputString(obj.ToolKind & vbCr)
       '    pane.OutputString("   " & obj.ToolName & vbCr)
       '    pane.OutputString("   " & obj.ToolPath & vbCr)
       'Next

   End Sub

Sincerely,
Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.
Johan Nilsson - 12 Jan 2006 10:38 GMT
Hi Ed,

thanks for your obviously knowledgeable reply. I have a few comments below.

> Hi Johan,
>
[quoted text clipped - 3 lines]
> do a rebuild. The problem with this though is that all the outputs of
> the previous build would wind up be deleted.

That isn't really an option for me, it sounds much too involved and kludgy.

> To get access to the actual VCPostBuildEventTool object for a VC
> project, you have use the IVCCollection interface. Below is a quick
> macro that will dump the various VCPostBuildEventTool properties to
> your output window. I cobbled that together before realizing there's
> no way to actually execute the tool programatically.

Thanks anyway - I could still use that in combination with the IVsLaunchPad
stuff (as you say below).

> I don't have a solution for launching that
> VCPostBuildEvent.CommandLine from a macro either. If you are
> in-process to devenv.exe, (from an addin or VSIP package) you could
> utilize the IVsLaunchPad service documented in the Visual Studio SDK.
> Like IDesignerHost, you can't actually get at this interface
> out-of-process.

Just to clarify - aren't the macros run in-process? If I've got the VS 2005
SDK installed, wouldn't it be possible to add the correct
references/assemblies to the macro project and access SVsLaunchPad?

Sorry it that's a silly question, but I've never really put in a lot of time
learning how the VS.NET extensibility works. I've just ordered the Inside
Visual Studio.NET 2003 book, though (and will order the 2005 counterpart
whenever it appears).

> If you have an addin, you can convert the DTE object to a COM
> IServiceProvider interface and call QueryService for the SVsLaunchPad
> service to retrieve an IVsLaunchPad interface. You could then use the
> ToolPath and CommandLine properties of the VCPostBuildEvent object to
> run the command(s) listed in the project settings.

[snip code]

What I perhaps should have said from the beginning is why I'd like to do
this:

One of my projects in the solution is the test driver, responsible for
running all tests. I want that driver to execute during each build (I'm
doing TDD development), so I've added the running of the driver as a
post-build event to it's own project.

However, once in a while I'd like to just rerun the tests in the same way -
without having to do some dummy editing in a source file to trigger a
compile/link/post-build action.

Thanks,

Johan Nilsson
"Ed Dore [MSFT]" - 12 Jan 2006 19:08 GMT
Hi Johan,

You're more than welcome. It took a bit of source code diving and some
hints from the dev team before I actually figured out how to retrieve that
VCPostBuildEventTool object :-)

Macros are actually run from another process (VSMSVR.EXE).  If you build an
addin, which runs inproc to the IDE, you can retrieve and leverage that
SVsLaunchPad service, but it's not accessible from that vsmsvr.exe process.

IMHO, Inside Visual Studio .Net is a must have book for anyone doing VS
automation or extensibility stuff.

It sounds like the best approach would be to create an addin, and implement
a command/toolbar button that to do this. Then you could just use the
command/toolbar button to fire off the postbuild commandline with
IVsLaunchPad. The only tricky part would be the expansion of any macros
like $(OutputDir), but I suspect this can be done using the
VCProjectEngine. I haven't actually investigated that particular problem as
of yet.

If you decide to go the addin route, and get stuck let me know. Given we
already know how to get at that VcPostBuidlEventTool now, it probably
wouldn't take much to throw together an addin that would launch that
commandline.

Sincerely,
Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.

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.