0

We have a visual studio package (VS Package) that references two class library projects: Project A and Project B. Project A in turn references another class library project (Project B).

So the dependency structure looks like this: VS Package -> Project A -> Project B

All projects exist inside the same solution and the dependencies have been set up as proper project references. When deploying the VS Package the assemblies from Project A and Project B are deployed to GAC. The assemblies are strong named. No binding redirection is specified.

We deploy several versions of the same VS package thus several versions of Project A and Project B assemblies are in GAC. The problem is that no matter which version of VS package is executed it always loads the latest assembly versions from GAC.

How can we force the correct version of the assembly to be loaded from GAC that is the version used when building the VS Package project?

Thanks.

Edited my original post to more accurately describe my situation.

Ciprian
  • 3,533
  • 1
  • 18
  • 22
  • Can you show the references in your question. – Reg Edit Sep 03 '14 at 12:50
  • Can you be more specific on this? – Ciprian Sep 03 '14 at 13:16
  • You presumably have lines such as `` in your web.config that reference the assemblies. – Reg Edit Sep 03 '14 at 13:24
  • The assembly is referenced through a ProjectReference: {2b48b2ba-6ea5-4b1d-a678-97dca29bd223} foo.vcs12 False – Ciprian Sep 03 '14 at 13:31
  • That's just for Visual Studio. Somewhere the deployed site is telling the framework about the reference at runtime. Doesn't your web.config have any lines like I showed? – Reg Edit Sep 03 '14 at 13:35
  • I don't have a web app. My application is a c# visual studio extension. I consists of three assembly files. The main assembly is loaded by visual studio. The other assemblies are deployed to GAC and used by the main assembly. – Ciprian Sep 03 '14 at 13:38
  • Sorry, my bad, thought you were asking about a web app for some reason. See my answer in that case. – Reg Edit Sep 03 '14 at 13:44
  • Are you changing the assembly version on the different versions? The GAC's notion of versions only recognizes the assembly version. – Mike Zboray Sep 03 '14 at 13:49
  • Yes the version of the assemblies is changed. I can see the different assembly versions deployed in GAC. – Ciprian Sep 03 '14 at 13:53
  • Then this shouldn't happen unless you are specifically redirecting to a new version. Do you have a policy file or a binding redirect in your app.config? – Mike Zboray Sep 03 '14 at 13:56
  • No I don't have a binding redirect. – Ciprian Sep 03 '14 at 14:02
  • Are you building and deploying on the same machine? Is your question how to get Visual Studio/MSBuild to pick up the desired version when building or how to get the desired version used when running the application? – Mike Zboray Sep 03 '14 at 14:10
  • I am deploying a clean VM. My question is: When running the app I want to load the exact assembly version that was used during build. – Ciprian Sep 03 '14 at 14:19

3 Answers3

1

This should do the trick , but I cant recommend it you should avoid using the GAC and have your librarys close.

Assembly SampleAssembly;
SampleAssembly = Assembly.LoadFrom("c:\\Sample.Assembly.dll");

For more information read the manual

Thorarins
  • 1,836
  • 16
  • 21
0

In the Properties window for the reference, you may set Specific Version to true.

enter image description here

Reg Edit
  • 6,719
  • 1
  • 35
  • 46
  • That option is not available if you have a project reference. – Ciprian Sep 03 '14 at 13:45
  • For some reason the main assembly does not load from GAC the same assembly version that was used during the project build – Ciprian Sep 03 '14 at 13:46
  • "Specific Version" is enforced at compile-time, not run-time. – Mike Zboray Sep 03 '14 at 13:47
  • Given the issue you've encountered, you probably want to change it to a dll reference, which will give you the version control you seek. – Reg Edit Sep 03 '14 at 13:48
  • @mike I agree, but how is this done for an assembly that is the output of a project. – Ciprian Sep 03 '14 at 13:50
  • @Ciprian You can't do it for a project reference because it doesn't make any sense. All "Specific Version" does is enforce that the version referenced in the proj file is the version used when compiling. Since the build system will look in several places for the assembly it may get the wrong one. Projects don't have versions. Assemblies do. – Mike Zboray Sep 03 '14 at 13:54
  • Yes, but what I thought the "Reference Output Assembly" option does just that, reference an assembly which happens to be the output of a project being built. May I'm wrong on this. – Ciprian Sep 03 '14 at 13:57
  • @mikez I think you may be mistaken? I've used `SpecificVersion` successfully to get an add-in to pick up the right version. Also see [this answer](http://stackoverflow.com/questions/1063459/net-reference-specificversion-true-or-false) – Reg Edit Sep 03 '14 at 13:59
  • @Ciprian to use a dll reference instead of a project reference, when adding a reference use the browse button to find the dll in the project bin folder (or preferably in a more controlled location where you've decided to keep the required version). – Reg Edit Sep 03 '14 at 14:06
0

You may add a Binding Redirect. This can be done at various levels such as machine, app, or by a publishing policy.

See here for guidance.

Reg Edit
  • 6,719
  • 1
  • 35
  • 46