2015-05-15 20 views
3

我正在ASP.NET Web應用程序項目(它是MVC)內的Visual Studio 2015 CTP 6中構建C#類。該課程需要閱讀RSS源,並根據此StackOverflow post,最好的方法是通過System.ServiceModel.Syndication命名空間。安裝ASP.NET 5.0版本的System.ServiceModel.Syndication

我試圖通過在Visual Studio的解決方案資源管理器中的web.app文件夾下右擊References來添加所需的DLL。然後我選擇添加引用...在對話框中,它沒有列出任何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類:

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 
+1

我在DNX Core WCF GitHub頁面[這裏]創建了一個問題(https://github.com/dotnet/wcf/issues/76)。請添加您的支持。 –

+1

完成。謝謝,@RehanSaeed。 – Alex

+0

你解決了這個「ServiceModel」問題嗎?我想使用「ServiceModel」從vnext web應用程序與windows服務進行通信,但有類似的錯誤... – user007

回答

4

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服務引用時問過類似的問題here

+3

對於任何人想知道,這進入'project.json'文件。 – Alex

+1

如何修改project.json文件?它已經有了物品。我們只是將它添加到它嗎?謝謝 – Alex

+1

是的 - 您可以手動添加或刪除project.json中的依賴項。 Visual Studio監視該文件中的更改,並將添加和刪除幕後的實際引用。給它一個:) – heymega