c# - How to call Workstation.GetLocalWorkspaceInfo in a way that works for those who use VS2012 and those who use VS2013 without reflection? -
workstation.current.getlocalworkspaceinfo(string)
returns workspaceinfo
object associated given local directory.
so, wrote simple programme displays workspace name given local directory name. works great on machine, not work on another.
the difference between 2 mine runs vs2012 , other 1 - vs2013. life of me, cannot understand it. both workspaces linked same tfs server 2010.
after reading tfs api: getlocalworkspaceinfo returns null replaced microsoft.teamfoundation.xxx references ones found on sec machine , worked again. but, of course, stopped working on machine.
it cannot right way. must doing wrong here.
i want single executable work both machines without resorting reflection. question simple - how?
the finish source code can found here - https://bitbucket.org/markkharitonov/tfsinsanity/src. basically, 2 projects sharing same source code, using different set of dependencies.
the main source code is:
private static workspace getworkspace(string wsroot, string wsname, string wsowner) { var coll = new tfsteamprojectcollection(new uri("http://torsvtfs01:8080/tfs/defaultcollection")); var vcs = (versioncontrolserver)coll.getservice(typeof(versioncontrolserver)); workspaceinfo wsinfo; if (wsroot == null) { console.writeline(workstation.current.name); wsinfo = workstation.current.getlocalworkspaceinfo(vcs, wsname, wsowner); if (wsinfo == null) { throw new exception(string.format("failed identify workspace {0};{1}", wsname, wsowner)); } } else { wsinfo = workstation.current.getlocalworkspaceinfo(wsroot); if (wsinfo == null) { throw new exception(string.format("failed identify workspace corresponding \"{0}\"", wsroot)); } } homecoming wsinfo.getworkspace(coll); }
here how works on machine (vs2012):
ps c:\work\getshelvedchangeset> tf workspaces collection: http://torsvtfs01:8080/tfs/defaultcollection workspace owner computer comment --------- -------------------- -------- ------------------------------------------------------------------------------------ canws212 dayforce\mkharitonov canws212 ps c:\work\getshelvedchangeset> .\bin\debug2012\getshelvedchangeset.exe --wsroot c:\dayforce\sharptop microsoft.teamfoundation.versioncontrol.client, version=11.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a workspace instance -784339741 comment: computer: canws212 effectivepermissions: 0 folders: [0] islocalworkspace: false lastaccessdate: 1/1/0001 12:00:00 name: canws212 options: 0 owneraliases: [0] ownerdisplayname: dayforce\mkharitonov owneridentifier: owneridentitytype: ownername: dayforce\mkharitonov owneruniquename: securitytoken: /canws212;34be4ed8-c4fd-4e9f-bdae-d1843df36b0f ps c:\work\getshelvedchangeset> .\bin\debug2013\getshelvedchangeset.exe --wsroot c:\dayforce\sharptop failed identify workspace corresponding "c:\dayforce\sharptop" ps c:\work\getshelvedchangeset>
and on other machine:
ps c:\tfs\dfgatedcheckintest2\build\2010\scripts> &"c:\program files (x86)\microsoft visual studio 12.0\common7\ide\tf.exe" workspaces collection: http://torsvtfs01:8080/tfs/defaultcollection workspace owner computer comment -------------------- ----------------- ------------ ---------------------------------------------------------------------------------------- 1733_torsvbuild10 dayforce\tfsbuild torsvbuild10 workspace created team build 1846_91_torsvbuild10 dayforce\tfsbuild torsvbuild10 workspace created team build 1846_92_torsvbuild10 dayforce\tfsbuild torsvbuild10 workspace created team build ps c:\tfs\dfgatedcheckintest2\build\2010\scripts> .\debug2012\getshelvedchangeset.exe --wsroot c:\tfs\dfgatedcheckintest2 failed identify workspace corresponding "c:\tfs\dfgatedcheckintest2" ps c:\tfs\dfgatedcheckintest2\build\2010\scripts> .\debug2013\getshelvedchangeset.exe --wsroot c:\tfs\dfgatedcheckintest2 microsoft.teamfoundation.versioncontrol.client, version=12.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a workspace instance 215494889 comment: workspace created team build computer: torsvbuild10 effectivepermissions: 0 folders: [0] islocalworkspace: false lastaccessdate: 1/1/0001 12:00:00 name: 1733_torsvbuild10 options: 0 owneraliases: [0] ownerdisplayname: dayforce\tfsbuild owneridentifier: owneridentitytype: ownername: dayforce\tfsbuild owneruniquename: securitytoken: /1733_torsvbuild10;f2899138-af14-4449-9f6d-78a0fbccebb8 ps c:\tfs\dfgatedcheckintest2\build\2010\scripts>
in case, method signatures should identical, need worry getting proper dll referenced in first place. should able link newer dll , utilize binding redirection load dll users have vs 2012 installed.
we used method in previous product provide tfs 2005 , 2008 compatibility.
in short, create custom assembly resolver. here effort load microsoft.teamfoundation.*
dlls vs 2012 when fail load vs 2013 versions linked against:
appdomain.currentdomain.assemblyresolve += new resolveeventhandler(resolveassembly); public static assembly resolveassembly(object sender, resolveeventargs args) { string[] arguments = args.name.split(new string[] { ", ", "," }, stringsplitoptions.removeemptyentries); string assemblyname = arguments[0]; if(assemblyname.startswith("microsoft.teamfoundation.", stringcomparison.currentcultureignorecase)) { homecoming assembly.load(assemblyname + ", version=11.0.0.0"); } homecoming null; }
(note should check requested version number , pass civilization info loader, outlined in blog post, snippet should sufficient started.)
c# visual-studio-2012 tfs visual-studio-2013
No comments:
Post a Comment