提问者:小点点

VS代码中的System.Windows.Forms程序集引用


若要在visual studio代码中设置C#开发框架,我希望使用System.Windows.Forms引用来设置窗口。

代码:

using System;
using System.Collections;
using System.Windows.Forms;
namespace Softwaredevelopment
{
   public partial class Form1 : Form
   {
      public Form1()
      {
        //tbd
      }
   }
}

我得到了错误:

缺少程序集引用。

我必须在project.json文件或.csproj文件中添加哪些内容才能创建窗口。


共1个答案

匿名用户

我想您可以将它添加到您的.csproj中,您还可以在这里找到名称和版本C:\windows\assembly

  <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <TargetFramework>net452</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.Drawing-dotnet-core" Version="1.2.3"/>

    <Reference Include="System.Windows.Forms" version="2.0.0.0" /> //< ----- add This line here

  </ItemGroup>
</Project>