Use ProvideBindingRedirection instead of ProvideCodeBase #928

Merged
merged 1 commit into from Apr 27, 2017

Conversation

Projects
None yet
3 participants
Contributor

jcansdale commented Mar 20, 2017 edited

In PR #914 I used the VS SDK ProvideCodeBase attribute to ensure that a particular version of an assembly will load from a specific CodeBase (into the Load context). For example:

[assembly: ProvideCodeBase(AssemblyName = "GitHub.Exports",
    CodeBase = @"$PackageFolder$\GitHub.Exports.dll")]

This can help if another extension references the exact version of an assembly that has been installed (with a ProvideCodeBase attribute). If however a different version is referenced, another assembly will be loaded with a different codebase, static fields and types. Unless our assembly has been designed with side-by-side execution in mind, the results could be unpredictable.

A resolution for this would be to sweep up multiple versions of an using the ProvideBindingRedirection attribute. For example:

[assembly: ProvideBindingRedirection(AssemblyName = "GitHub.Exports",
    CodeBase = @"$PackageFolder$\GitHub.Exports.dll",
    OldVersionLowerBound = "0.0.0.0", OldVersionUpperBound = "2.2.0.9")]

This would prevent old versions of an assembly being loaded at the same time as the current one (they would be redirected to the current one). This would also allowing 3rd party extensions that could work with multiple newer versions of GHfVS (rather than having to be built against a specific version).

This PR depends on #914.
Fixes #926
See #923

Contributor

jcansdale commented Mar 20, 2017 edited

There appear to be some bugs when using the ProvideBindingRedirection attribute, which I had to work around. The following doesn't appear to work:

[assembly: ProvideBindingRedirection(AssemblyName = "GitHub.Exports",
    CodeBase = @"$PackageFolder$\GitHub.Exports.dll",
    OldVersionLowerBound = "0.0.0.0", OldVersionUpperBound = "Current")]

(IIRC, this only redirects 0.0.0.0 to the current version 😭)

I had more luck with the following:

[assembly: ProvideBindingRedirection(AssemblyName = "GitHub.Exports",
    CodeBase = @"$PackageFolder$\GitHub.Exports.dll",
    OldVersionLowerBound = "LowestMajor", OldVersionUpperBound = "Current")]

(This redirects all assemblies with the same major version number to the current version)

We could use this for Splat, Rothko, etc. who's assembly versions we don't have constants defined for. For the GitHub.* assemblies, we could take advantage of AssemblyVersionInformation.Version.

I believe the following would work:

[assembly: ProvideBindingRedirection(AssemblyName = "GitHub.Exports",
    CodeBase = @"$PackageFolder$\GitHub.Exports.dll",
    OldVersionLowerBound = "0.0.0.0", OldVersionUpperBound = AssemblyVersionInformation.Version)]

@jcansdale jcansdale requested review from shana and grokys Mar 20, 2017

Collaborator

shana commented Mar 24, 2017

We could use this for Splat, Rothko, etc. who's assembly versions we don't have constants defined for.

Do we need it for those? We will likely never bump versions on our dependencies (except Octokit), so if we need to hardcode things for them, that should be fine.

Contributor

jcansdale commented Mar 24, 2017 edited

Do we need it for those? We will likely never bump versions on our dependencies (except Octokit), so if we need to hardcode things for them, that should be fine.

Using the following form (with LowestMajor and Current) works fine if we're only interested in a single major version number:

[assembly: ProvideBindingRedirection(AssemblyName = "Octokit",
    CodeBase = @"$PackageFolder$\Octokit.dll",
    OldVersionLowerBound = "LowestMajor", OldVersionUpperBound = "Current")]

Since we're not likely to bump versions, this certainly applies here. 😄

It just confused me for a while that it isn't possible to use 0.0.0.0 in combination with Current (it failed silently and only bound 0.0.0.0) IIRC! 😕

Here are the current versions we're using:

LibGit2Sharp, Version=0.22.0.0, Culture=neutral, PublicKeyToken=7cbde695407f0333
Rothko, Version=0.0.1.0, Culture=neutral, PublicKeyToken=9f664c41f503810a
Splat, Version=1.6.2.0, Culture=neutral, PublicKeyToken=79cb2fa33d9108a3
Octokit, Version=0.22.0.0, Culture=neutral, PublicKeyToken=5525be5bc50478ea

Can I double-check these are use keys generated by us for GHfVS?

Collaborator

shana commented Mar 24, 2017

All the submodule projects have their own keys checked in, so you can check those. Libgit2sharp is a nuget package so that's not signed by us. There's also ReactiveUI and Akavache on the list of things we depend on and sign ourselves, I believe?

Contributor

jcansdale commented Mar 28, 2017

Libgit2sharp is a nuget package so that's not signed by us.

I've changed it to only provide redirections for GitHub.* assemblies. People shouldn't be using a different version of these inside the same VS instance.

Doing this for Libgit2sharp or any other assembly that might be used by another extension would be a bad thing.

I'm still wondering about Octokit, because it is part of our interface and the version is likely to be bumped in future. It probably should be redirected as well...

@shana

shana approved these changes Mar 29, 2017 View changes

Collaborator

shana commented Mar 30, 2017

I assume we have to wait for #914 to get merged before this one can be merged?

Contributor

jcansdale commented Apr 3, 2017

I assume we have to wait for #914 to get merged before this one can be merged?

@shana Yes, and ideally #947 as well. I tried merging this one in as well, but it was proving to be a pain (the combination of a .sln and submodule merge 😕). It obviously can be done, but I'm sure there is less painful way! I've suggested a zoom chat with Jasmine to discuss.

@grokys

grokys approved these changes Apr 4, 2017 View changes

jcansdale changed the base branch to master from fixes/885-remove-assembly-resolver Apr 6, 2017

Contributor

jcansdale commented Apr 27, 2017

Fixes #926

@jcansdale jcansdale Use ProvideBindingRedirection for GHfVS assemblies
Redirect to the latest `GitHub.*` assembly for assemblies that require a CodeBase (e.g. `GitHub.Exports`).
This makes extensions that don't depend on a specific GHfVS version possible.
fef1f8c

jcansdale merged commit 549e5f7 into master Apr 27, 2017

5 checks passed

GitHub CLA @jcansdale has accepted the GitHub Contributor License Agreement.
Details
VisualStudio Build #6400253 succeeded in 90s
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
jenkins/build_log Jenkins Build Log
Details

jcansdale deleted the fixes/926-ProvideBindingRedirection branch Apr 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment