I am trying to create a (simple) windows form application in Visual Studio Code 2017. Sadly I am unable to use the full VS versions, so I don't have the menu options to create new projects.
Previously, I have created console projects by running dotnet new console from the terminal in VSC. However, I can't get this to work with a forms application.
The following extensions are installed from the Marketplace:
What I tried:
1
Create console application, and reference using System.Windows.Forms;: However, this requires me to reference this namespace:
The type or namespace 'Forms' does not exist in the namespace "System.Windows"
So I tried to add this using the NuGet Package Manager: Add Package command, but here I can't find the package System.Windows.Forms.
One last thing I could think of was to manually add a reference to the .csproj file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3"/>
<PackageReference Include="System.Windows.Forms" HintPath = "\..\WINDOWS\Microsoft.NET\Framework\v4.0.30319"/>
</ItemGroup>
</Project>
But when running dotnet restore this gives warnings:
warning NU1604: Project dependency System.Windows.Forms does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results.
warning NU1701: Package 'System.Windows.Forms 4.0.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
And when run gives the following exception:
System.BadImageFormatException: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
2
Create a single .cs file, and compile that with csc. This way I can use Forms, but I lose the functionality of dotnet handling other dependencies.
Question
I feel like this issue suffers from the XY problem. I am new to C# and .NET, so I am not sure where I am failing, whether what I am trying to do is even possible.
So my question is, how do I create a windows forms application using the dotnet new command?


Newtonsoft.Jsonpackage. Which would be a different question altogether. Since that wouldn't directly be a solution, I am interested to know whether it is possible to do withdotnet.