How can VS automatically add assemblies to the GAC?
You can get Visual Studio to automatically add strong-named assemblies to the GAC by using Post-Build events:
- Right-click your project and select Properties from the shortcut menu.
- In the left pane select Build Events (C#) or Compile and the Build Events button (VB .NET).
- In the Post-build Event Command Line box add the following commands:
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\GACUTIL" -U "$(TargetName)" "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\GACUTIL" -I "$(TargetPath)" /f
In Visual Studio, add the following commands in the macro window:
"$(DevEnvDir)..\..\SDK\v2.0\bin\GACUTIL" -U "$(TargetName)" "$(DevEnvDir)..\..\SDK\v2.0\bin\GACUTIL" -I "$(TargetPath)" /f
The first command unregisters the old assembly from the GAC and the second line installs the new version of the assembly.
- Click OK to save the commands, then click OK to close the Properties dialog.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 07/21/11
Comment or report problem with topic
