我正在尝试编写一个简单的 WCF 服务,用于向 Azure 服务总线发布消息。
我正在使用 Visual Studio 2019,并使用 Visual Studio 中的模板为框架 4.8 创建了一个新的 WCF 服务项目。
然后我将添加 Microsoft.Azure.ServiceBus nuget 包。当我从 nugget 包中引用一个类时,我得到一个编译错误。
例如添加代码:
var client = new QueueClient("connection", "myqueue");
产生以下编译错误:
CS0012 The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
我尝试添加 NETStandard.Library nuget 包,包括最新版本和 v 2.0.0,但没有任何区别。
我已经确认它肯定针对框架 4.8。
该项目是作为网站项目生成的,因此没有 csproj 文件并且对正在构建的内容的控制有限。
我的代码如下,纯wcf服务模板代码加一行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Microsoft.Azure.ServiceBus;
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code, svc and config file together.
public class Service : IService
{
public string GetData(int value)
{
var client = new QueueClient("connection", "myqueue"); //COMPILE ERROR!!!
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
我已将这些步骤复制到一个控制台应用程序中,该应用程序编译良好且不要求提供 netstandard 库参考。