Strongly naming a 3rd party assembly - Could not load file or assembly

前端 未结 3 1739
野趣味
野趣味 2021-02-05 15:38

I am writing a Visual Studio 2012 extension, for internal use, which requires that all assemblies have a strong name. I am dependent on RestSharp (and a few other dlls), and si

相关标签:
3条回答
  • 2021-02-05 16:19

    I wrote a NuGet solution level package to help with strong naming 3rd party assemblies with your own key.

    This is targeted for signing the contents of NuGet packages that are using unsigned assemblies, in order to be able to link to these packages where the consuming project is strongly named. Access to the original source code is not required, and you may sign any assembly with your own strong naming key. You may also delay-sign if desired.

    https://nuget.org/packages/Nivot.StrongNaming

    You can read more about it on my blog:

    http://www.nivot.org/blog/post/2013/04/30/Signing-unsigned-assemblies-in-NuGet-packages

    0 讨论(0)
  • 2021-02-05 16:21

    A few things you can check:

    It seems you project refrence is still to the unsigned dll .\RestSharp.dll. You should compile your project against the signed .\Signed\RestSharp.dll dll. Remove the current refrences and add the again.

    Also check the dll in the bin directory of your project. It's possible the old RestSharp.dll is still there. Remove it and check all build directories.

    You can also check if the restsharp.dll is in you GAC. If so remove the dll from your gac.

    0 讨论(0)
  • 2021-02-05 16:30

    I tried to use RestSharp from VSPackage and it works. My steps to add RestSharp:

    1. Add RestSharp by NuGet in a project where I will use it. To do this, right-click on the project in Solution Explorer and selecting the “Manage NuGet Packages…”, find RestSharp and press Install button.

    2. Write test code in this project:

      
      var test = new RestSharp.RestClient("http://test.com");
      Logger.Log(Category.Info, "Test {0}", test.BaseUrl);
      
    3. Add RestSharp by NuGet in the installer project. Similarly paragraph 1. I use the VSIX Deployment Package. To set the necessary assembly just need to add a reference to assembly in the VSIX Deployment Package. This makes the “Manage NuGet Packages…” command. When you create a VSPackage by VS Wizard, the main project of VSPackage is VSIX Deployment Package.

      If you use another method of installation your VS extension (for example, MSI installer), you need to explicitly add RestSharp.dll to our installation package.

    As a result, I got line "Test http://test.com" in the log.

    Most likely in your case, that RestSharp.dll been not installed and therefore VS is not finding RestSharp.dll when loading your module. Or the fully qualified name of installed RestSharp assembly is different from the fully qualified name assembly in References of project. To see this check out whether RestSharp.dll file in folder of your extension (for VSPackage by default patch is "%LOCALAPPDATA%\MICROSOFT\VISUALSTUDIO\11.0EXP\EXTENSIONS\{YourCompanyName}\{YourProductName}\{YourProductVersion}\"). You can see the absolute path to your extension in the Modules window if run the extension under the debugger.

    Edit: I just now noticed that the RestSharp assembly from NuGet has not a strong name. So the directory of installed extension and References of projects should contain the exact same assembly with a strong name, and everything will work fine.

    0 讨论(0)
提交回复
热议问题