Microsoft KB Archive/810230

= How to implement build events in Visual C# .NET or Visual C# 2005 =

Article ID: 810230

Article Last Modified on 1/10/2007

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C# 2005 Express Edition

-



IN THIS TASK

 * SUMMARY
 * Use a Visual C++ Makefile Project to Implement Build Events
 * Use the PrePostBuildRules Add-In to Implement Build Events
 * REFERENCES



IMPORTANT: This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows Registry



SUMMARY
This step-by-step article describes how to implement build events in Visual C# .NET or Visual C# 2005.

When you use build events, you can specify an action that occurs at a specific time during the build process. For example, you can specify a post-build event to register a file by using regsvr32.exe. You can also view and make a change to a generated assembly in the GAC (Global Assembly Cache) by using the Gacutil.exe tool.

In Visual C# .NET or Visual C# 2005, there are no direct methods to specify pre-build and post-build events.

back to the top

Use a Visual C++ Makefile Project to Implement Build Events
Build events are a built-in feature of Microsoft Visual C++ .NET projects. You can implement these events in a Visual C# .NET or Visual C# 2005 project by including a Visual C++ .NET Makefile project in the solution. To implement pre-build events, you must make the Visual C++ .NET Makefile project dependant on the Visual C# .NET or Visual C# 2005 project. To implement post-build events, you must make the Visual C# .NET or Visual C# 2005 project dependant on the Visual C++ .NET Makefile project.

To do this, follow these steps:  Open your existing Visual C# .NET or Visual C# 2005 solution. On the File menu, point to Add Project, and then click New Project. Under Project Types, click Visual C++ Projects, and under Templates, click MakeFile Project.

Note In Visual Studio 2005, &quot;Visual C++ Projects&quot; should be changed to &quot;Visual C++.&quot; Type the name for the solution, specify a location for the solution, and then click OK. In the Makefile Application Wizard, click Finish. On the Project menu of the Makefile Project, click Properties. In the Configuration Type box, select Utility, and then click OK.</li> On the Project menu, click Project Dependencies…. To perform the pre-build events, follow these steps: <ol style="list-style-type: lower-alpha;"> On the Dependencies tab, select the appropriate Visual C# .NET project from the Projects list, and then under Depends on, click the Visual C++ Makefile project .</li> Click OK to apply the change. This makes sure that the Visual C# .NET or Visual C# 2005 project is built last.</li> Right-click the Visual C++ Makefile project in Solution Explorer, and then click Properties.</li>  Click Build Events, and then specify the pre-build event command.

For example, to copy the file before building, specify the following: copy c:\AddinReg.reg $(OutDir) </li></ol> </li> To perform the post-build setup, follow these steps: <ol style="list-style-type: lower-alpha;"> Click the Visual C++ Makefile project in the Projects list, and then select the appropriate Visual C# .NET or Visual C# 2005 project under Depends on.</li> Click OK to apply the change. This makes sure that the Visual C++ project is built last.</li> Right-click the Visual C++ Makefile project in Solution Explorer, click Properties, and then click Build Events to specify the post-build event command.</li></ol> </li></ol>

back to the top

Use the PrePostBuildRules Add-In to Implement Build Events
<ol> This add-in provides pre-build and post-build rules at the solution and project levels.

To download the add-in, see the the following Microsoft Web site:

http://download.microsoft.com/download/VisualStudioNET/Samples/7.0/NT5XP/EN-US/BuildRules.exe

WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

To use this add-in, follow these steps : <ol> Load the solution file with this source, and then build the solution.</li> On Tools menu, click Add-In Manager. If the Add-In Manager is already open, close it, and then open it again.

Note If the new add-in appears in the Add-In Manager list of add-ins, you have successfully registered the add-in.</li> If the add-in does not appear in the Add-In Manager list, follow the steps to register it manually: <ol style="list-style-type: lower-alpha;"> Locate the AddinReg.reg file in the BuildRules folder.</li> Right-click AddinReg.reg, and then click Merge. Click Yes when prompted to add the entries to the registry.</li> <li>The new entries made to the registry can be seen in the following location:

</li></ol> </li> <li>Start a new instance of Visual Studio .NET or Visual Studio 2005.</li> <li>On the Tools menu, click the new add-in.</li> <li>A dialog box appears that allows you to select the solution or project, and to add rules to it.</li> <li>When you add a rule, you can specify the name echo as the program name to display raw text in the output window.</li></ol> </li></ol>

back to the top

<div class="references_section">