[英]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.