首页 > 解决方案 > 警告 MSB3290:无法为类型库创建包装程序集

问题描述

我试图添加 System_Windows_Forms 参考 COM 参考。但是当我添加它时,我得到了这个错误

Microsoft.Common.CurrentVersion.targets(2701,5): warning MSB3290: Failed to create the wrapper assembly for type library "{215d64d2-031c-33c7-96e3-61794cd1ee61}". Type library 'System_Windows_Forms' was exported from a CLR assembly and cannot be re-imported as a CLR assembly.

顺便说一句,我在控制台应用程序上,出于某种原因,我没有看到一个节点,而是看到了Reference一个Dependencies节点,尽管我怀疑这很重要。

我也尝试添加不同的参考,Interop.IWshRunTimeLibrary有效,但System.Drawing.dll没有

标签: c#visual-studioreference

解决方案


如果您正在运行控制台应用程序,您将无法引用或加载System.Windows.Forms依赖项。同样,这些与对象System.Drawing直接相关,因此不能作为控制台依赖项访问,这就是您收到该错误的原因。FormForm

更新:要检查控制台应用程序中的按键,请使用Console.Readkey()方法。这是一个使用示例Console.ReadKey()

using System;

class CheckKeyPress
{
    public static void Main()
   {
     ConsoleKeyInfo cki;
     Console.TreatControlCAsInput = true; //Prevents from ending if CTL+C is pressed

      Console.Writeline("Press any CTL, ALT, or SHIFT");
      Console.Writeline("Press ESC key to quit: \n");
   do
     {
       cki = Console.ReadKey();
      Console.Write("You Pressed: ");
      if ((cki.Modifiers & ConsoleModifiers.ALT) != 0) Console.Write("ALT+");
      if ((cki.Modifiers & ConsoleModifiers.SHIFT) != 0) Console.Write("SHIFT+");
      if ((cki.Modifiers & ConsoleModifiers.CTL) != 0) Console.Write("CTL+");
      Console.WriteLine(cki.Key.ToString());
    } while (cki.Key != ConsoleKey.Escape);
  }
}

推荐阅读