【问题标题】:How to reference assemblies using Visual Studio Code?如何使用 Visual Studio Code 引用程序集?
【发布时间】:2015-10-31 12:30:05
【问题描述】:

我想在我使用 OSX 上的 Visual Studio Code 编写的控制台应用程序中引用 System.Drawing.dll。即我想使用这些 using 语句

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

为了避免这个构建错误

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

我找不到这方面的教程,我什至不知道 dll 是否可用于 .net core 或 mono 或任何可视化工作室代码使用。

【问题讨论】:

  • GDI 和 GDI+ 在 OS X 上不可用。
  • 那么有什么类似的我可以使用吗?
  • 从菜单添加:项目:添加参考:网络选项卡:System.Drawing
  • @jdweng “Visual Studio Code”中没有项目菜单

标签: c# visual-studio-code


【解决方案1】:

在您的 .csproj 文件中,将您的依赖项作为 PackageReference 添加到 ItemGroup 中,然后运行 ​​dotnet restorenuget restore。示例:

<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>

查看this article 以获得完整说明。

【讨论】:

  • 这个答案不再正确,因为project.json 未在较新版本的 .NET Core 中使用(已移至 .csproj 项目文件格式。)
  • 感谢@PerLundberg 我更新了我的答案以反映这一点。
  • 引用 wsdl Web 服务怎么样?可以加地址吗。 csproject 和恢复项目?
  • @AProgrammer 我不熟悉 WSDL,但据我所知,nuget restore/dotnet restore 仅适用于 nuget 包。
【解决方案2】:

新的 .NET Core SDK 恢复命令是 dotnet restore

要在 Visual Studio Code 中添加任何程序集引用,请参阅我的post

【讨论】:

  • 我无法添加 System.Web.Script 以使用 JavaScriptSerializer。
【解决方案3】:

Mono 提供了一个您可以利用的WinForms pipeline implementation,其中包括对System.Drawing 的支持。

【讨论】:

  • 问题不在于如何专门添加 System.Drawing。它询问如何使用 Visual Studio Code 添加对任何程序集的引用。
猜你喜欢
  • 2017-01-15
  • 2017-06-19
  • 1970-01-01
  • 1970-01-01
  • 2017-10-04
  • 2012-01-23
  • 1970-01-01
  • 2010-09-18
  • 2018-12-02
相关资源
最近更新 更多