安装System.ServiceModel.Syndication的ASP.NET 5.0版本 [英] Install ASP.NET 5.0 version of System.ServiceModel.Syndication

查看:104
本文介绍了安装System.ServiceModel.Syndication的ASP.NET 5.0版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET Web应用程序项目(它是MVC)的Visual Studio 2015 CTP 6中构建一个C#类.该类需要阅读RSS提要,并根据此

I'm building a C# class in Visual Studio 2015 CTP 6, within an ASP.NET Web Application project (it's MVC). The class needs to read RSS feeds, and according to this StackOverflow post, the best way to do this is via the System.ServiceModel.Syndication namespace.

我尝试通过右键单击Visual Studio解决方案资源管理器中web.app文件夹下的References来添加此所需的DLL.然后,我选择了添加引用... .在对话框中,它没有列出任何ASP.NET 5.0库.它只列出了各种库的4.0版本.所以我添加了System.ServiceModel(4.0.0.0).

I tried adding the DLL needed for this by right-clicking References under the web.app folder in Visual Studio's Solution Explorer. Then I selected Add Reference... In the dialog box, it didn't have any ASP.NET 5.0 libraries listed; it only had the 4.0 version of various libraries listed. So I added System.ServiceModel (4.0.0.0).

现在Visual Studio抛出这些错误:

Now Visual Studio is throwing these errors:

...\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课:

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);
        }
    }
}

如何解决此问题?谢谢.

How do I resolve this issue? Thank you.

更新:按照heymega的建议修改了project.json文件. project.json文件的相关部分如下所示:

Update: Modified the project.json file as recommended by heymega. Here's what the project.json file's pertinent section looks like:

"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"
        }
    }
},

从此开始,这会引发很多错误:

This throws many errors, starting with this:

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,因此您不能将其用作核心库的一部分.

System.ServiceModel hasn't been ported to ASP.NET 5 yet so you can't use it as part of the core library.

您应该能够包括标准aspnet50项目(非核心)的参考.

You should be able to include the reference for a standard aspnet50 project (Not core).

{
    "commands": {
        "run": "run"
    },
    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "Microsoft.AspNet.Mvc": "6.0.0-beta2"
            },
            "frameworkAssemblies": {
                "System.ServiceModel": "4.0.0.0"
            }
        }
    }
}

在尝试添加一个此处时,我问了类似的问题. WCF服务参考.

I asked a similar question here when trying to add a WCF service reference.

这篇关于安装System.ServiceModel.Syndication的ASP.NET 5.0版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆