我不明白如何在 Visual Studio 2019 中使用这个 NuGet 包管理器
我从 Nuget 包管理器安装了 Grpc.Tools 包。
我单击了解决方案包旁边的复选框, 但它显示没有参考
using Grpc.Core;
我在任何地方的引用下都没有看到 Grpc.Core,
当我搜索参考资料时,我在任何地方都找不到 GRPC
我是否遗漏了什么,还有其他安装步骤吗?
我的代码很简单,如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Grpc.Core;
namespace gRPCtest
{
public class Server : Form
{
public Server()
{
Text = "Server Window";
Size = new System.Drawing.Size(300, 200);
}
}
public class Client : Form
{
public Client()
{
Text = "Client Window";
Size = new System.Drawing.Size(300, 200);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Create a new instance of the child window
Server serverForm = new Server();
serverForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
// Create a new instance of the child window
Client clientForm = new Client();
clientForm.Show();
}
}
}
在终端中,我尝试运行以下命令并收到错误:
PS C:\Users\Waymo\Desktop\prf.net\gRPCtest> NuGet\Install-Package Grpc.Core
NuGet\Install-Package : The module 'NuGet' could not be loaded. For more information, run 'Import-Module NuGet'.
At line:1 char:1
+ NuGet\Install-Package Grpc.Core
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (NuGet\Install-Package:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
PS C:\Users\Waymo\Desktop\prf.net\gRPCtest> Import-Module NuGet
Import-Module : The specified module 'NuGet' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module NuGet
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (NuGet:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
.NET Framework 实际上并未实现 HTTP/2,而这是 gRPC 协议的要求。因此,.NET Framework 对基于 HTTP/2 的 gRPC 的支持有限。
看来您是在WinForms(.net框架)项目中执行了上述操作。同样,我在Winforms(.net框架)项目中也遇到了和你类似的情况。添加成功后,gRPC Tools 没有出现在项目引用中。
但是在Winforms(指基于.net的Winforms)中,gRPC Tools可以成功添加引用。您可以使用基于.net的Winforms来进行相应的操作。
详情请参考:
https://learn.microsoft.com/en-us/aspnet/core/grpc/netstandard?view=aspnetcore-6.0#net-framework