每个版本上的 GAC 安装 - 如何可靠地安装
当我使用 Visual Studio 编译应用程序时,我希望能够在 GAC 中可靠地自动安装我的应用程序程序集。我已经在我的 Web 应用程序的构建中设置了构建前和构建后事件。
预构建事件:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /f /ul Uninstall.Gac.txt
构建后事件:
"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"
如您所见,我还在回收我的 Web 应用程序池,以便新程序集开始工作。
我遇到的问题是这是一个非常不可靠的过程。如果我的 Web 应用程序失败,我的下一个构建将失败,因为卸载将失败(构建后未在上一个构建上运行)...等等。
我想让这个过程尽可能可靠。我想有条件地卸载和程序集(如果它们存在)并强制安装,无论它们是否存在...但预构建事件仍然很重要,原因如下:
重要 重要
的是我的所有程序集都完全卸载在构建发生之前,否则它们不会复制到我的输出目录(因为编译器在 GAC 中找到它们),因此 GAC 安装会失败,因为它在输出 \bin 文件夹中找不到程序集。
我应该如何在我的 Web 应用程序构建上可靠地卸载和安装 GAC?
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 important 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能仅依靠 GACUTIL 工具来编写 GAC 安装/卸载程序吗?使用代码,您至少可以依赖 hresults 错误代码并做出相应的反应。
有关 GAC API 的信息可在此处找到:
http:// /blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx
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
如果构建成功,请将输出程序集复制到另一个目录并从那里安装到 GAC 中。在预构建中,使用此目录从 GAC 中删除这些程序集。
这样,编译期间 GAC 中就不会出现任何程序集。仅当通过在批处理文件中验证所有输出文件是否存在而成功构建了所有二进制文件时,您才可以调整构建后以复制二进制文件。
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.