Search code examples
c#visual-studio-2010pre-build-event

Equivalent to VCPostBuildEventTool for C# project in visual studio 2010


I am writing an add-in for visual studio, which creates a test project for a production code project. It should support C, C++ and C# projects. for C/C++ projects I can progarmatically set the post and pre-build events using VCPostBuildEventTool.

this how I get it from the Project object:

VCProject vcTestProj = (VCProject)testProj.Object;
IVCCollection testProjCfgs = (IVCCollection)vcTestProj.Configurations;
VCConfiguration testProjDebugCfg = (VCConfiguration)testProjCfgs.Item("Debug");
VCLinkerTool testProjLinkerTool = (VCLinkerTool)((IVCCollection)testProjDebugCfg.Tools).Item("VCLinkerTool");
VCCLCompilerTool testProjectCompileTool = (VCCLCompilerTool)((IVCCollection)testProjDebugCfg.Tools).Item("C/C++ Compiler Tool");
VCPreBuildEventTool testProjPreBuildTool = (VCPreBuildEventTool)((IVCCollection)testProjDebugCfg.Tools).Item("Pre-Build Event Tool");
VCPostBuildEventTool testProjPostBuildTool = (VCPostBuildEventTool)((IVCCollection)testProjDebugCfg.Tools).Item("Post-Build Event Tool");

But a C# project can not be used as a VCProject, and I can't find a way to access it's pre and post build events progarmatically. Anyway to do that?


Solution

  • C#/VB.NET projects are treated as the same, so they are part of ProjectProperties3 (or ProjectProperties2) interface,

    http://msdn.microsoft.com/en-us/library/vslangproj2.projectproperties2.postbuildevent.aspx

    How to get to that level is mentioned in

    http://msdn.microsoft.com/en-us/library/ms228958.aspx