13

我正在编写一个供内部使用的 Visual Studio 2012 扩展,它要求所有程序集都有一个强名称。我依赖于 RestSharp(和其他一些 dll),并且由于它没有强命名,因此我通过遵循this为其添加了一个强名称。一切都根据过程的输出进行,甚至 Visual Studio 声称如果我查看项目引用中 RestSharp.dll 的属性,它是强命名的。但是,当我使用我的扩展程序时,我得到一个 FileLoadException 声明:

无法加载文件或程序集“RestSharp,Version=104.1.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。需要强命名程序集。(来自 HRESULT 的异常:0x80131044)

有关如何解决此问题或解决此问题的任何想法?

4

3 回答 3

5

我编写了一个 NuGet 解决方案级别包,以帮助使用您自己的密钥对第 3 方程序集进行强命名。

这旨在对使用未签名程序集的 NuGet 包的内容进行签名,以便能够链接到使用项目被强命名的这些包。不需要访问原始源代码,您可以使用自己的强命名密钥对任何程序集进行签名。如果需要,您也可以延迟签名。

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

你可以在我的博客上阅读更多关于它的信息:

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

于 2013-05-12T21:56:03.313 回答
1

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.

于 2012-12-24T17:58:46.290 回答
0

您可以检查几件事:

看来您的项目引用仍然是未签名的 dll .\RestSharp.dll。您应该针对已签名的 .\Signed\RestSharp.dll dll 编译您的项目。删除当前引用并再次添加。

还要检查项目 bin 目录中的 dll。旧的 RestSharp.dll 可能仍然存在。删除它并检查所有构建目录。

您还可以检查restsharp.dll 是否在您的GAC 中。如果是这样,请从您的 gac 中删除 dll。

于 2012-12-21T15:04:56.023 回答