{"action":"opened","issue":{"url":"https://api.github.com/repos/praeclarum/FuGetGallery/issues/29","repository_url":"https://api.github.com/repos/praeclarum/FuGetGallery","labels_url":"https://api.github.com/repos/praeclarum/FuGetGallery/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/praeclarum/FuGetGallery/issues/29/comments","events_url":"https://api.github.com/repos/praeclarum/FuGetGallery/issues/29/events","html_url":"https://github.com/praeclarum/FuGetGallery/issues/29","id":330020016,"node_id":"MDU6SXNzdWUzMzAwMjAwMTY=","number":29,"title":"Show binding redirects for strongly signed assemblies","user":{"login":"dotnetjunkie","id":1506621,"node_id":"MDQ6VXNlcjE1MDY2MjE=","avatar_url":"https://avatars1.githubusercontent.com/u/1506621?v=4","gravatar_id":"","url":"https://api.github.com/users/dotnetjunkie","html_url":"https://github.com/dotnetjunkie","followers_url":"https://api.github.com/users/dotnetjunkie/followers","following_url":"https://api.github.com/users/dotnetjunkie/following{/other_user}","gists_url":"https://api.github.com/users/dotnetjunkie/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnetjunkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnetjunkie/subscriptions","organizations_url":"https://api.github.com/users/dotnetjunkie/orgs","repos_url":"https://api.github.com/users/dotnetjunkie/repos","events_url":"https://api.github.com/users/dotnetjunkie/events{/privacy}","received_events_url":"https://api.github.com/users/dotnetjunkie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-06T20:27:30Z","updated_at":"2018-06-06T20:27:30Z","closed_at":null,"author_association":"NONE","body":"Binding redirects are a constant pain when dealing with strongly signed assemblies, especially when they are references a lot, such as Newtonsoft.Json.\r\n\r\nTo easy this paint, it would be really nice if Fuget could show a binding redirect example for strongly signed assemblies.\r\n\r\nFor instance, this is an example that you could show when viewing the Newtonsoft.Json package:\r\n\r\n``` xml\r\n<runtime>\r\n  <assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\">\r\n    <dependentAssembly>\r\n\t  <assemblyIdentity name=\"Newtonsoft.Json\" publicKeyToken=\"30ad4fe6b2a6aeed\" \r\n            culture=\"neutral\" />\r\n\t  <bindingRedirect oldVersion=\"0.0.0.0-11.0.0.0\" newVersion=\"11.0.0.0\" />\r\n    </dependentAssembly>\r\n  </assemblyBinding>\r\n</runtime>\r\n```\r\n\r\nOnly the package version and the `publicKeyToken` have to be injected. I imagine this to be the template:\r\n\r\n``` xml\r\n<runtime>\r\n  <assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\">\r\n    <dependentAssembly>\r\n\t  <assemblyIdentity name=\"Newtonsoft.Json\" publicKeyToken=\"{publicKeyToken}\" \r\n            culture=\"neutral\" />\r\n\t  <bindingRedirect oldVersion=\"0.0.0.0-{assemblyVersion}\" newVersion=\"{assemlyVersion}\" />\r\n    </dependentAssembly>\r\n  </assemblyBinding>\r\n</runtime>\r\n```\r\nTo be able to achieve this, two things need to be extracted from the dll itself:\r\n\r\n- The public key token\r\n- The assembly version, which can be something different than the NuGet package version.\r\n\r\nThe public key toekn can be received at runtime as follows:\r\n\r\n``` c#\r\nAssembly assembly = Assembly.ReflectionOnlyLoadFrom(\"path\");\r\n\r\nvar publicKeyToken = \r\n    assembly.FullName.Split(new[] { \", \" }, StringSplitOptions.None)\r\n    .Where(p => p.StartsWith(\"PublicKeyToken=\"))\r\n    .Select(p => p.Substring(\"PublicKeyToken=\".Length))\r\n    .FirstOrDefault();\r\n```\r\nIf the `publicKeyToken` variable is `null`, it means the assembly is not signed and no binding redirect is required."}}
{"actor":{"display_login":"dotnetjunkie"}}