Reputation: 7561
My C#/.NET program compiles as AnyCPU
, and references Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll
, which is installed with Visual Studio (or Team Explorer). My program must run on computers without VS installed, both 32- and 64-bit, so I have to bring this assembly with my program. It currently runs on 32-bit computers, but not on 64-bit, since it can't load this assembly.
After build, in bin\Debug I get a 32-bit version of this assembly, which VS presumably takes from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll
. This is how the program works on 32-bit computers. But my program also runs as 64-bit locally, and the 32-bit assembly gets loaded, how can that be? To check, I wrote me a little PowerShell:
param([string] $path)
$AssemblyName = [Reflection.Assembly]::Loadfile($path).GetName()
write-output $AssemblyName | fl
And ran it as both 32-bit and 64-bit:
> powershell.exe -ExecutionPolicy ByPass -f .\f.ps1 Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll
(...)
CodeBase : file:///C:/windows/assembly/GAC_64/Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader/11.0.0.0
> C:\Windows\SysWow64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -f .\f.ps1 Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll
(...)
CodeBase : file:///C:/windows/assembly/GAC_32/Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader/11.0.0.0__b03f5f7f11d50a3a/Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll
Ah, looks like VS installed the assembly to the GAC in both 32- and 64-bit, and the .NET loader knows to load the correct one.
My question: How can I simulate such behavior when I can't install VS?
Upvotes: 3
Views: 2620
Reputation: 43625
I am not sure you can redistribute this assembly with your program since they are part of Visual Studio. At least you would need to look at what parts and how you can redistribute the Visual Studio SDK where this assembly is part of. See here and here.
They are also part of the TFS Object Model, but you can't distribute the assemblies from that package either. You can however ask users to download and install that before using your software. And it seems that they are 32 bits only, so you would still need to compile your application as 32 bits.
An alternative would be using the webservices directly. See here. You can call them AnyCPU without problems.
Upvotes: 1
Reputation: 141
You can try installing the assembly in GAC programmatically by leveraging fusion API.
More details here: http://www.codeproject.com/Articles/8285/GAC-API-Interface
Upvotes: 0