How to add .Net Core built-in assembly, say, System.Windows.Forms, to a C# project in VS Code?
This can easily be done in Visual Studio by using the Reference Manager. However, I got stuck with VS Code. There is tutorial on how to add assembly from NuGet Package but I couldn't find one about adding .Net Core assembly.
Updated: I tried what Nsevens said to have the following reference.
<ItemGroup>
<Reference Include="System.Windows.Forms">
<HintPath>thePath\System.Windows.Forms.dll</HintPath>
</Reference>
</ItemGroup>
There was no problem found in editor and it could be compiled successfully.
But, In debug mode the program vanishes immediately after starting debugging. Debug console says
The program '[(some number)] MyProgram.dll' has exited with code 0 (0x0).
If the exe is run directly, it fails and the console says
Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
Unhandled 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. (0x80131058) File name: 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.BadImageFormatException: Cannot load a reference assembly for execution. at MyProgram.Program.Main(String[] args)
Add the following code to the project file (.csproj)
<ItemGroup>
<Reference Include="MyAssembly">
<HintPath>path\to\MyAssembly.dll</HintPath>
</Reference>
</ItemGroup>
(from: https://medium.com/@tonerdo/referencing-a-net-dll-directly-using-the-net-core-toolchain-16f0af46a4dc)
User contributions licensed under CC BY-SA 3.0