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

查看:168
本文介绍了在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文件中的<TargetFramework>元素.

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

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

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