8000 Use ProvideBindingRedirection instead of ProvideCodeBase by jcansdale · Pull Request #928 · github/VisualStudio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Use ProvideBindingRedirection instead of ProvideCodeBase #928

Merged
merged 1 commit into from
Apr 27, 2017

Conversation

jcansdale
Copy link
Collaborator
@jcansdale jcansdale commented Mar 20, 2017

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

@jcansdale
Copy link
Collaborator Author
jcansdale commented Mar 20, 2017

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 March 20, 2017 13:13
@shana
Copy link
Contributor
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.

@jcansdale
Copy link
Collaborator Author
jcansdale commented Mar 24, 2017

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?

@shana
Copy link
Contributor
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?

@jcansdale
Copy link
Collaborator Author

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...

@jcansdale jcansdale force-pushed the fixes/926-ProvideBindingRedirection branch from d7dcbe3 to 6b19170 Compare March 28, 2017 18:01
@shana
Copy link
Contributor
shana commented Mar 30, 2017

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

@jcansdale
Copy link
Collaborator Author

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.

@jcansdale jcansdale force-pushed the fixes/885-remove-assembly-resolver branch from 5368dce to c88337e Compare April 4, 2017 15:15
@jcansdale jcansdale changed the base branch from fixes/885-remove-assembly-resolver to master April 6, 2017 10:48
@jcansdale jcansdale force-pushed the fixes/926-ProvideBindingRedirection branch from 6b19170 to 9e8d49f Compare April 27, 2017 08:44
@jcansdale
Copy link
Collaborator Author

Fixes #926

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.
@jcansdale jcansdale force-pushed the fixes/926-ProvideBindingRedirection branch from 676e638 to fef1f8c Compare April 27, 2017 09:30
@jcansdale jcansdale merged commit 549e5f7 into master Apr 27, 2017
@jcansdale jcansdale deleted the fixes/926-ProvideBindingRedirection branch April 27, 2017 09:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0