If you are writing Windows Forms code in a .Net Core app, then it's very probable that you run into this error:
Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
If you are using the Sdk style project file (which is recommended) your *.csproj file should be similar to this:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>WinExe</OutputType>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>MyAppNamespace</RootNamespace>
<AssemblyName>MyAppName</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.0.0" />
</ItemGroup>
</Project>
Pay extra attention to these lines:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<OutputType>WinExe</OutputType>
<UseWindowsForms>true</UseWindowsForms>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.0.0" />
Note that if you are using WPF while referencing some WinForms libraries you should add <UseWPF>true</UseWPF>
as well.
Hint: Since .NET 5.0, Microsoft recommends to refer to SDK Microsoft.Net.Sdk
in lieu of Microsoft.Net.Sdk.WindowsDesktop
.