31

I would like to reference the System.Drawing.dll in a console app I am writing using Visual Studio Code on OSX. i.e. I want to use these using statements

using System.Drawing;
using System.Drawing.Imaging;

to avoid this build error

Program.cs(56,20): error CS0246: The type or namespace name `Bitmap' could not be found. Are you missing an assembly reference?

I can't find a tutorial on this, I don't even know if the dll is available in .net core or mono or whatever visual-studio-code uses.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Peter
  • 7,792
  • 9
  • 63
  • 94

3 Answers3

16

In your .csproj file, add your dependency as a PackageReference in an ItemGroup, then run dotnet restore or nuget restore. Example:

<ItemGroup>
  <Reference Include="System" />
  <Reference Include="System.Xml" />
  <Reference Include="System.Core" />
  <Reference Include="Xamarin.iOS" />
  <PackageReference Include="Realm" Version="2.1.0" />
  <PackageReference Include="xunit">
    <Version>2.3.1</Version>
  </PackageReference>
</ItemGroup>

Take a look at this article for a full explanation.

Ahmad
  • 603
  • 1
  • 8
  • 17
  • 1
    This answer is no longer correct since `project.json` isn't used in more recent versions of .NET Core (moved to `.csproj` project file format.) – Per Lundberg Mar 03 '18 at 20:37
  • 1
    Thanks @PerLundberg I updated my answer to reflect this. – Ahmad Mar 05 '18 at 03:25
  • How about referencing to a wsdl web service? Can I add the address to. Csproject and restore project? – A Programmer Mar 13 '18 at 15:40
  • @AProgrammer I'm not familiar with WSDL, but `nuget restore`/`dotnet restore` is only for nuget packages as far as I know. – Ahmad Jun 15 '18 at 01:02
14

The new .NET Core SDK restore command is dotnet restore

To add any asssembly reference in Visual Studio Code, please refer to my post.

Bhawna Jain
  • 709
  • 10
  • 27
ikolim
  • 15,721
  • 2
  • 19
  • 29
0

Mono offers a WinForms pipeline implementation that you can leverage, that includes support for System.Drawing.

Den
  • 16,686
  • 4
  • 47
  • 87
  • 3
    the question isn't really about how to add System.Drawing specifically. It is asking how can I add a reference to ANY assembly using Visual Studio Code. – Peter Nov 03 '15 at 21:29