简体   繁体   English

Visual Studio C# 我可以使用哪个 Class 库项目引用 Blazor 项目

[英]Visual Studio C# with which Class Library Projects can I reference a Blazor Project

I want to write a C# library for my MongoDB CRUD operations in Visual Studio 2019. And use this library later in different projects.我想在 Visual Studio 2019 中为我的 MongoDB CRUD 操作编写一个 C# 库。稍后在不同的项目中使用这个库。 I want to use the library in Blazor (.net core) and in WinForms (.net Framework).我想在 Blazor (.net core) 和 WinForms (.net Framework) 中使用该库。 What project-type of "Class Library" do I have to choose?我必须选择什么项目类型的“类库”? (I did try "library net Core" and "Winforms .net framework" -> didn't work) (我确实尝试过“库网络核心”和“Winforms .net 框架”-> 没用)

Question 1: Is it project-type ".Net Standard Library"?问题1:是项目类型的“.Net标准库”吗?

Question 2: How do I use/activate the Library in the Blazor Project?问题 2:如何使用/激活 Blazor 项目中的库? In Winforms, I right-click (References) and add the DLL to the WinformsProject, add an unsing statement and it works.在 Winforms 中,我右键单击 (References) 并将 DLL 添加到 WinformsProject,添加一个 unsing 语句,它就可以工作了。

But in Blazor there is only Dependencies (no references).但是在 Blazor 中只有依赖项(没有引用)。 I did add "Project Reference" and choose the dll I could not get it to work.我确实添加了“项目参考”并选择了 dll 我无法让它工作。 Do I need to add a COM Reference?我是否需要添加 COM 参考?

In short: How do I use a ClassLibrary is Blazor?简而言之:如何使用 ClassLibrary 是 Blazor? What ClassLibrary type do I need?我需要什么 ClassLibrary 类型? How can I then later use this Library in the Blazor Project (I guess this step needs to be explained step by step because I'm so noob)?我以后如何在 Blazor 项目中使用这个库(我想这一步需要逐步解释,因为我太菜鸟了)?

Thx for your Answer谢谢你的回答

I want to use the library in Blazor (.net core) and in WinForms (.net Framework).我想在 Blazor (.net core) 和 WinForms (.net Framework) 中使用该库。

It would be slightly easier and advisable to use WinForms on .NET core, which is now in a usable state.在 .NET 内核上使用 WinForms 会稍微容易一些,也更可取,该内核现在位于可用的 state 中。 Much more future-proof.更具前瞻性。

Your options depend on your MongoDb access library (I assume you're not starting form scratch).您的选择取决于您的 MongoDb 访问库(我假设您没有从头开始)。 It will probably support .net standard.它可能会支持 .net 标准。 .net standard is the common ground for .net 4.x and .net Core , so that is your best choice here. .net 标准.net 4.x.net 内核的共同点,因此这是您的最佳选择。

I did add "Project Reference" and choose the dll I could not get it to work.我确实添加了“项目参考”并选择了 dll 我无法让它工作。

That is the way to go though.这就是 go 的方式。 You didn't specify "could not get it to work", that would have helped.您没有指定“无法使其正常工作”,那会有所帮助。

But you won't be able to use this from Blazor Webassembly (client-side).但是您将无法从 Blazor Webassembly(客户端)使用它。 You can only access this from Blazor server or a separate API server.您只能从 Blazor 服务器或单独的 API 服务器访问它。

Do I need to add a COM Reference.我是否需要添加 COM 参考。

Absolutely not.绝对不。

I guess this step needs to be explaint step by step我想这一步需要一步一步解释

Add a ".net standard classlibrary" to your solution.将“.net 标准类库”添加到您的解决方案中。 Reference the MongoDb driver from this library, make sure it works.从这个库中引用 MongoDb 驱动程序,确保它工作正常。 You probably want .net standard 2.0 or lower when you use WinForms on .net 4.x.当您在 .net 4.x 上使用 WinForms 时,您可能需要 .net 标准 2.0 或更低版本。 standard 2.0 is the highest level for .net classic.标准 2.0 是 .net 经典的最高级别。

Then add references to this class lib from both your WinForms and Blazor (server) projects.然后从您的 WinForms 和 Blazor(服务器)项目中添加对此 class 库的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio 2010中引用C#类库项目? - How to reference a C# Class Library project in Visual Studio 2010? 我可以在Visual Studio 2010(C#)中引用引用的库吗 - Can I reference a referenced library in Visual Studio 2010 (C#) 如何公开由类库引用的类库,该类库随后作为项目引用包含在Visual Studio中? - How do I expose class libraries referenced by a class library, which is then included as a project reference in Visual Studio? 我可以在 Visual Studio 中添加一个 C# 类作为资源,以便我可以方便地添加到新项目中吗? - Can I add a C# class in visual studio as resource so I can add to new projects conveniently? 缺少Visual C#项目类库 - Missing Visual C# Projects Class Library 如何在“ Visual Studio 2013”​​中创建由其他库项目组成的统一c#库项目 - How to create an unifying c# library project in “visual studio 2013” consisting of other library projects 将通用Windows C#类库引用添加到通用Windows C ++ DLL项目Visual Studio 2015 - Adding a Universal Windows C# Class Library reference to a Universal Windows C++ DLL project Visual Studio 2015 您可以拆分 Visual Studio 项目 (c#) 并引用它吗? - Can you split a visual studio project (c#) and reference it? 如何在我的 C# Visual Studio 项目中添加 VC++ DLL 作为参考? - How can I add a VC++ DLL as a reference in my C# Visual Studio project? Visual Studio C#项目参考无法正常工作 - Visual Studio C# Project Reference not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM