您的位置:首页 > 运维架构

Getting a copy of a DLL in the GAC

2007-08-21 12:22 309 查看

GettingacopyofaDLLintheGAC

Afewweeksago,PatrickWellinkbloggedabouthowyouwouldgetacopyofaDLLwhenit'sintheGAC.TodayIhadthesameproblembutafterreadingPatrick'sblogpostandthecomments,Idecidedtowriteasmallconsoleapplicationtomakethatprocesssomewhateasier.

Thisapplicationtakesatleasttwoarguments.ThefirstargumentisthephysicalpathtotheGAConthesystem.ThesecondisthepathwheretheDLLneedstobecopied.ThefollowingexamplecopiesallCrystalcomponentsintheGACtoabackupfolder:

GetGACAssembliesC:\Windows\AssemblyC:\Projects\GACBackupCrystal*.dll

IfyoujustneedabackupofallGACassemblies,simplydosomethinglikethis:

GetGACAssembliesC:\Windows\AssemblyC:\Projects\GACBackup

Tobuildtheapplication,IusedtheScanDirectoryclassIbloggedaboutearlier.Thecodeforthisconsoleapplicationisreallysimple:

usingSystem;
usingSystem.IO;
namespaceGetGACAssemblies
{
classProgram
{
privatestaticstring_targetPath;
staticvoidMain(string[]args)
{
//Youneedatleasttwoarguments
if(args.Length>=2)
{
//Getthetargetpathandmakesureitexists
_targetPath=args[1];
if(!_targetPath.EndsWith(@"\"))
{
_targetPath+=@"\";
}
if(!Directory.Exists(_targetPath))
{
Directory.CreateDirectory(_targetPath);
}
//Setupthedirectoryscannerobject
ScanDirectoryscanner=newScanDirectory();
scanner.FileEvent+=newScanDirectory.FileEventHandler(scanner_FileEvent);
if(args.Length==2)
{
scanner.SearchPattern="*.dll";
}
else
{
scanner.SearchPattern=args[2];
}
//Startthescan
scanner.WalkDirectory(args[0]);
}
}
staticvoidscanner_FileEvent(objectsender,FileEventArgse)
{
stringnewFile=_targetPath+e.Info.Name;
if(File.Exists(newFile))
{
File.Delete(newFile);
}
File.Copy(e.Info.FullName,newFile);
}
}
}

Youcandownloadthecodefortheconsoleapplicationhere.

GettingacopyofaDLLthat'sonlyintheGAC

Okprobablythereisasimpelerwayofdoingthisbutigoogledforitandcouldn'tfindit.Sohereisthestory.

IneededaspecificDLLthatwasplacedintheGACbytheinstallofBizTalk.IneededtheDLLcauseIneededtoadareferenceinmyC#project.IfanybodyknowshowtoaddaReferencetoaDLLtha'sintheGACI'llbeinterestedaswell.

ButIcouldn'tfindawaytodoitsoIneededacopyofthatdll.

SoyouuseexplorerandBrowsetotheGAC.



Butyoucan'tmakeacopyofit,Youcanseeallthedetailsandstuffbutyoucannotcopyit.ButifyouopenaCommandpromptandgotothesamedirectorystufflooksdifferent....



AndforsurewhenyougotothecorrectdirectoryyoucangettheunderlyingDLL.



ThereareprobablyeasierwaysofdoingthisbutIthoughtIsharethismethodofdoingit.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐