How to make the Assembly automatically added to GAC during compilation

Source: Internet
Author: User

If your project requires someProgramThe Set exists in GAC, but those sets are generated when you compile another project, or are dynamically changed for other reasons, the best practice is to re-add these assembly to GAC when compiling the project.

If your GAC contains the assembly of your project because of deployment and other work, and you cannot add breakpoint debugging and so on, this kind of thing often happens, it is also a good solution to re-add these assembly to GAC when compiling the project.

The idea of automatically adding an assembly to GAC during compilation is very simple. It is to write a batch file and then call this batch file in the project generation event. The specific implementation is as follows:

1. Create a register.batfile under your project directory and use the Microsoft gacutil.exetool in batch processing. The location of the gacutil.exe tool varies depending on the operating system version. XP is v6.0a, While Vista and win7 are v7.0a. Assume that you have two projects: myproject1 and myproject2. myproject1 is an executable file, and myproject2 is a dynamic link library.

@ Echo off

Set Path = % PATH %; C: \ Program Files \ microsoft sdks \ windows \ v7.0a \ bin;

Set solutionpath = c: \ Users \ cyljxu \ Documents \ Visual Studio 2008 \ projects \ windowsformsapplication17 \

Gacutil/if "% solutionpath % myproject1 \ bin \ % ~ 1 \ myproject1.exe"
Gacutil/if "% solutionpath % myproject2 \ bin \ % ~ 1 \ myproject2.dll"

Exit 0

Note: \ bin \ % ~ 1 \ % ~ 1 indicates the compilation configuration, such as debug or release.

2. Open the properties page of the project and add a post-build event command line:

Call "$ (projectdir) Register. Bat" $ (configurationname )"


1. All the assembly to be added to GAC must be signed.

2. Because gacutil commands require administrator permissions, you must run ide as administrator in Vista and win7.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.