如何引用使用Visual Studio代码组件? [英] How to reference assemblies using Visual Studio Code?

查看:215
本文介绍了如何引用使用Visual Studio代码组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想引用System.Drawing.dll程序在一个控制台应用程序,我在OSX使用Visual Studio编写代码。即我想用这些using语句

 使用System.Drawing中; 
使用System.Drawing.Imaging;

要避免这种情况的生成错误

 的Program.cs(56,20):错误CS0246:类型或命名空间名称'位图'无法找到。你是否缺少程序集引用? 



我无法找到这个教程中,我甚至不知道如果DLL可用在.NET核或单或其他视觉工作室代码使用。


解决方案

要添加程序集引用您必须添加在目标框架下的 project.json 文件的依赖(dnx451,dnxcore50),你可以这样来做:



假设你想SQLite.NET-PCL:



首先加入project.json



<$你的依赖p $ p> {
版本:1.0.0- *,
说明:控制台应用程序,
的作者:[ ],
标签:],
projectUrl:,
licenseUrl:,
工具:{
DefaultNamespace的:ConsoleApplication
},

依赖:{
//从来没有尝试过这个说实话
},

命令:{
ems_dataparser:ems_dataparser
},

框架:{
dnx451:{
依赖:{
的SQLite净PCL:1.0.11//添加.NET兼容4.5.1这里包
}
},
dnxcore50:{
依赖:{
Micr​​osoft.CSharp:4.0.1-β-23516,
System.Collections中:4.0.11-β- 23516,
System.Console:4.0.0-β-23516,
System.Linq的:4.0.1-β-23516,
系统。线程:4.0.11-β-23516,
的SQLite净PCL:1.0.11//添加ASP核心兼容包这里
}
}
}
}



然后用DNU恢复下载的依赖



OmniSharp很擅长暗示的依赖及其版本号,当你填写了这一点。你添加的依赖,运行后DNU在终端窗口中为您 project.json 文件的位置恢复。这将通过搜索和下载的NuGet他们解决的依赖。另外,VS代码会建议你尽快恢复为你增添一份新的依赖到你的 project.json 。然后,您可以使用新的包在你的项目。



要意识到哪些框架您的目标,哪些属于依赖的地方。


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.

解决方案

To add an assembly reference you have to add it as a dependency in the project.json file under the targeted framework (dnx451, dnxcore50) you can do it this way:

Let's say you want SQLite.NET-PCL:

First add your dependency in project.json

{
  "version": "1.0.0-*",
  "description": "Console Application",
  "authors": [ "" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
  "tooling": {
    "defaultNamespace": "ConsoleApplication"
  },

  "dependencies": {
    // never tried this to be honest
  },

  "commands": {
    "ems_dataparser": "ems_dataparser"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "sqlite-net-pcl": "1.0.11" // add .NET 4.5.1 compatible packages here
      }
    },
    "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Console": "4.0.0-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Threading": "4.0.11-beta-23516",
        "sqlite-net-pcl": "1.0.11" // add ASP Core compatible packages here
      }
    }
  }
}

Then use dnu restore to download the dependencies

OmniSharp is pretty good at suggesting dependencies and their version numbers when you're filling this out. After you add your dependency, run dnu restore in a terminal window at the location of your project.json file. This will resolve any dependencies by searching and downloading them from nuget. Alternatively, VS Code will suggest that your restore as soon as you add a new dependency to your project.json. You may then use the new package in your project.

Be conscious of what frameworks you are targeting and what dependencies belong where.

这篇关于如何引用使用Visual Studio代码组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆