安装 ASP.NET 5.0 版本 System.ServiceModel.Syndication
Install ASP.NET 5.0 version of System.ServiceModel.Syndication
我正在 Visual Studio 2015 CTP 6 中的 ASP.NET Web 应用程序项目(它是 MVC)中构建一个 C# class。 class 需要读取 RSS 提要,根据这个 Whosebug post,最好的方法是通过 System.ServiceModel.Syndication
命名空间。
我尝试通过右键单击 Visual Studio 解决方案资源管理器中 web.app
文件夹下的 References
添加为此所需的 DLL。然后我选择 Add Reference... 在对话框中,它没有列出任何 ASP.NET 5.0 库;它只列出了各种库的 4.0 版本。所以我添加了 System.ServiceModel
(4.0.0.0).
现在 Visual Studio 抛出这些错误:
...\src\web.app\Models\RssFeedModels.cs(4,14): ASP.NET Core 5.0 error CS0234: The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?)
...\src\web.app\Models\RssFeedModels.cs(21,17): ASP.NET Core 5.0 error CS0246: The type or namespace name 'SyndicationFeed' could not be found (are you missing a using directive or an assembly reference?)
...\src\web.app\Models\RssFeedModels.cs(25,20): ASP.NET Core 5.0 error CS0103: The name 'SyndicationFeed' does not exist in the current context
这是我的 RssFeedModels.cs
class:
using System;
using System.Collections.Generic;
using System.Xml;
using System.ServiceModel.Syndication;
namespace web.app.Models
{
public class Rss
{
public string Title { get; set; }
public string ContentSnippet { get; set; }
public string Content { get; set; }
public string PubDate { get; set; }
}
public class RssFeedModels
{
private XmlReader reader;
private SyndicationFeed feed;
public RssFeedModels(string url) {
reader = XmlReader.Create(url);
feed = SyndicationFeed.Load(reader);
}
}
}
如何解决这个问题?谢谢。
更新:根据heymega
的建议修改了project.json
文件。 project.json
文件的相关部分如下所示:
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
"gen": "Microsoft.Framework.CodeGeneration",
"ef": "EntityFramework.Commands",
"run": "run"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { },
"aspnet50": {
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta2"
},
"frameworkAssemblies": {
"System.ServiceModel": "4.0.0.0"
}
}
},
这会抛出很多错误,首先是:
The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?) web.app.DNX 4.5.1
System.ServiceModel
尚未移植到 ASP.NET 5
,因此您不能将其用作核心库的一部分。
您应该能够包含标准 aspnet50
项目(非核心)的参考。
{
"commands": {
"run": "run"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta2"
},
"frameworkAssemblies": {
"System.ServiceModel": "4.0.0.0"
}
}
}
}
我在尝试添加 WCF 服务引用时问了一个类似的问题。
我正在 Visual Studio 2015 CTP 6 中的 ASP.NET Web 应用程序项目(它是 MVC)中构建一个 C# class。 class 需要读取 RSS 提要,根据这个 Whosebug post,最好的方法是通过 System.ServiceModel.Syndication
命名空间。
我尝试通过右键单击 Visual Studio 解决方案资源管理器中 web.app
文件夹下的 References
添加为此所需的 DLL。然后我选择 Add Reference... 在对话框中,它没有列出任何 ASP.NET 5.0 库;它只列出了各种库的 4.0 版本。所以我添加了 System.ServiceModel
(4.0.0.0).
现在 Visual Studio 抛出这些错误:
...\src\web.app\Models\RssFeedModels.cs(4,14): ASP.NET Core 5.0 error CS0234: The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?)
...\src\web.app\Models\RssFeedModels.cs(21,17): ASP.NET Core 5.0 error CS0246: The type or namespace name 'SyndicationFeed' could not be found (are you missing a using directive or an assembly reference?)
...\src\web.app\Models\RssFeedModels.cs(25,20): ASP.NET Core 5.0 error CS0103: The name 'SyndicationFeed' does not exist in the current context
这是我的 RssFeedModels.cs
class:
using System;
using System.Collections.Generic;
using System.Xml;
using System.ServiceModel.Syndication;
namespace web.app.Models
{
public class Rss
{
public string Title { get; set; }
public string ContentSnippet { get; set; }
public string Content { get; set; }
public string PubDate { get; set; }
}
public class RssFeedModels
{
private XmlReader reader;
private SyndicationFeed feed;
public RssFeedModels(string url) {
reader = XmlReader.Create(url);
feed = SyndicationFeed.Load(reader);
}
}
}
如何解决这个问题?谢谢。
更新:根据heymega
的建议修改了project.json
文件。 project.json
文件的相关部分如下所示:
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
"gen": "Microsoft.Framework.CodeGeneration",
"ef": "EntityFramework.Commands",
"run": "run"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { },
"aspnet50": {
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta2"
},
"frameworkAssemblies": {
"System.ServiceModel": "4.0.0.0"
}
}
},
这会抛出很多错误,首先是:
The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?) web.app.DNX 4.5.1
System.ServiceModel
尚未移植到 ASP.NET 5
,因此您不能将其用作核心库的一部分。
您应该能够包含标准 aspnet50
项目(非核心)的参考。
{
"commands": {
"run": "run"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta2"
},
"frameworkAssemblies": {
"System.ServiceModel": "4.0.0.0"
}
}
}
}
我在尝试添加 WCF 服务引用时问了一个类似的问题