开发者

GAC installation on every build - how to do it reliably

I would like to reliably auto-install my application assemblies in the GAC when I compile my application using Visual Studio. I've setup pre- and post-build events in my web application's build.

Pre build event:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /f /ul Uninstall.Gac.txt

Post build event:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /f /il Install.Gac.txt
%windir%\system32\inetsrv\appcmd.exe recycle apppool -apppool.name:"Sharepoint IIS WebApps"

As you can see I'm also recycling my web application pool for the new assemblies to start working.

The problem I'm having is that this is a very unreliable process. In case my Web application fails, my next build will fail because uninstall will fail (post-build didn't run on previous build)... Etc.

I would like to make this process ass reliable as possible. I would like to conditionally uninstall and assemblies if they are present and forcibly install no matter whether they're there or not... But pre-build event is still import开发者_开发知识库ant for the next reason:

Important

It's important that all my assemblies are completely uninstalled before build takes place, otherwise they're not copied to my output directory (since compiler finds them in GAC) hence GAC install fails since it can't find assemblies in the output \bin folder.

How should I reliably do GAC uninstallation and installation on my web application build?


Instead onrelying on the GACUTIL tool, couldn't you program GAC install/uninstall? With code, you could at least rely on hresults error codes and react accordingly.

Information on the GAC API can be found here:

http://blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx


If the build succeeds, copy the output assemblies to another directory and install into GAC from there. And in pre-build use this directory to remove these assemblies from GAC.

This way there should never be any assemblies in GAC during compilation. You can tweak the post-build to copy the binaries only if all of them were successfully built by verifying in batch file if all output files EXIST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜