在 Visual Studio 代码中创建类库 [英] Creating a class library in visual studio code

查看:37
本文介绍了在 Visual Studio 代码中创建类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,假设我没有 Windows 操作系统,有一个 Linux.我创建了一个 .Net 核心控制台应用程序,还想创建一个类库并在控制台应用程序中引用它.我无法找到我是否能够做到,也无法在 Microsoft .Net 核心页面上找到示例.vs代码中有扩展吗?或者它不可能吗?如果我弄错了,你能指导我吗?

It might be a silly question, Let's say I don't have a Windows OS, have a Linux. I have created a .Net core console app, also want to create a class library and reference it in console app. I can't find if i am able to do it also couldn't find a sample on Microsoft .Net core page. Is there an extension in vs code? Or isn't it possible with it? If i am mistaken could you please guide me?

推荐答案

最好的方法是从控制台执行此操作,因为您正在使用最新支持的模板.VSCode 也有一个集成终端,您可以使用它.

The best way to do it is from the console, since you are using the latest supported templates this way. VSCode also has an integrated terminal you can use for this.

$ dotnet new lib -o MyLib
$ dotnet new sln #assuming there is no .sln file yet. if there is, skip this
$ dotnet sln add MyLib/MyLib.csproj
$ cd MyConsoleApp
$ dotnet add reference ../MyLib/MyLib.csproj

如果你需要不同的框架,你可以使用-f参数:

If you need different frameworks, you can use the -f argument:

$ dotnet new lib -o MyLib -f netcoreapp2.0

或手动更改生成的 .csproj 文件中的 元素.

or manually change the <TargetFramework> element inside the generated .csproj file.

这篇关于在 Visual Studio 代码中创建类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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