简体   繁体   English

在Visual Studio扩展中未执行引用的代码

[英]Referenced Code not executing in Visual Studio Extension

I have a Visual Studio Extension (VSIX package) that shows a WinForms dialog and then returns a string that is inserted into the code editor window in VS. 我有一个Visual Studio Extension(VSIX程序包),它显示一个WinForms对话框,然后返回一个插入VS中的代码编辑器窗口的字符串。

The WinForm loads fine. WinForm加载正常。 I can return a hard coded string and VS puts it into the editor. 我可以返回一个硬编码的字符串,VS会将其放入编辑器中。 However, if the WinForm makes a call to a 3rd party library (it is a .Net Core class library) it stops execution without an exception I can see and closes the form out. 但是,如果WinForm调用第三方库(它是.Net Core类库),它将停止执行,没有异常,我可以看到并关闭该窗体。 To test further, I had the referenced library simply return a hard coded string so there wasn't risk of an Exception in that code and it failed it (which makes me believe it's the action of calling the library.. if I step through this with a debugger it will not execute a procedure that makes a called to the referenced library.. if I comment out that line it will step through that procedure). 为了进行进一步测试,我让引用的库仅返回一个硬编码的字符串,因此该代码中没有发生异常的风险,并且它失败了(这使我相信这是调用该库的操作。使用调试器,它将不会执行对被引用库进行调用的过程。如果我注释掉该行,它将逐步执行该过程。 If I pluck the form out and put it in a WinForms app it executes as expected. 如果我拔出表单并将其放入WinForms应用程序中,它将按预期执行。

The referenced library was loaded into the extension via a local NuGet feed. 引用的库通过本地NuGet提要加载到扩展中。

  1. The 3rd party library isn't signed currently, could that be the issue? 第三方库当前未签名,这可能是问题吗?
  2. The 3rd party library is a "Class Library (.Net Core)".. there's no option I can see through the GUI to sign the library like you can with traditional class libraries (although this targets .Net 4.6). 第三方库是“类库(.Net核心)” ..我无法像通过传统类库那样,通过GUI看到对库进行签名的任何选项(尽管该目标是.Net 4.6)。 The WinForm itself can call it if it's in a different solution, it barfs when run through the VS Extension. 如果在其他解决方案中,WinForm本身可以调用它,但在VS Extension中运行时,它会发出响声。
  3. What else could cause this problem? 还有什么可能导致此问题?

Side note, this is an extension for myself and not general distribution. 旁注,这是对我自己的扩展,而不是一般发行。

Will post this for posterity. 将其发布以供后代使用。 Visual Studio appears stop the execution of the code in the extension when it makes a call out to an unsigned assembly. 当Visual Studio调用未签名的程序集时,它将停止扩展中代码的执行。 I tested this by signing the 3rd party assemblies (it then worked). 我通过签署第三方大会对此进行了测试(然后开始工作)。 The VSIX also signs itself by default if you use the template to create that project in Visual Studio. 如果您使用模板在Visual Studio中创建该项目,则VSIX在默认情况下也会自行签名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM