Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference assemblies using Visual Studio Code?

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.

like image 639
Peter Avatar asked Aug 08 '15 00:08

Peter


People also ask

How do I reference assemblies in C#?

In the Project Designer, click the References tab. Click the Add button to open the Add Reference dialog box. In the Add Reference dialog box, select the tab indicating the type of component you want to reference. Select the components you want to reference, and then click OK.

How do you reference codes in Visual Studio?

You can use the Find All References command to find where particular code elements are referenced throughout your codebase. The Find All References command is available on the context (right-click) menu of the element you want to find references to. Or, if you are a keyboard user, press Shift + F12.

What is assembly reference?

Reference assemblies are usually distributed with the Software Development Kit (SDK) of a particular platform or library. Using a reference assembly enables developers to build programs that target a specific library version without having the full implementation assembly for that version.


1 Answers

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.

like image 158
Ahmad Avatar answered Oct 09 '22 08:10

Ahmad