Problems with RavenDB.Client reference in asp.net 5.0 project.json

坚强是说给别人听的谎言 提交于 2019-11-28 09:04:10

问题


I'm trying to build a RavenApiController with the new ASP.NET 5.0 (aka Asp.Net vNext) stuff and can't seem to get the RavenDB.Client references to work at all.

The error I get is

Error CS0246 The type or namespace name 'Raven' could not be found (are you missing a using directive or an assembly reference?) SharedIO.ASP.NET Core 5.0 RavenApiController.cs 3

My project.json is as follows

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
    "wwwroot"
],
"packExclude": [
    "**.kproj",
    "**.user",
    "**.vspscc"
],
"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta2",
    "RavenDB.Client": "3.0.3599",
    "SharedIOModel": "1.0.0-*"
},
"frameworks": {
    "aspnet50": {},
    "aspnetcore50": {}
}

}

The code for RavenApiController.cs which fails to build on the third line begins as:

    using System;
    using Microsoft.AspNet.Mvc;
    using Raven.Client;
    using Raven.Client.Document;;

    namespace SharedIO.Controllers
    {
        [RequireHttps]
        public abstract class RavenAPIController : Controller
        {
            public IDocumentStore Store
            {
                get { return LazyDocStore.Value; }
            }

Totally stumped.

For what it's worth intellisense seems to be able to find the reference just fine and I don't get an error until I actually 'build solution.

Also Intellisense shows me that (for example) Raven.Client.Document.IDocumentStore is 'Available' in ASP.NET 5.0 but 'Not Available' in 'ASP.NET Core 5.0'.


回答1:


The problem is that you referencing RavenDB.Client in the top level dependencies node in project.json. That means that those dependencies are applicable to both Desktop CLR (aspnet50) and CoreCLR (aspnetcore50).

When you build an ASPNET 5 project, all configurations are built, not just the "active" one. Mostly sure RavenDB.Client works only with the Desktop CLR so move it under a dependencies node under that configuration.

"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta2",
    "SharedIOModel": "1.0.0-*"
},
"frameworks": {
    "aspnet50": {
        "dependencies" : {
            "RavenDB.Client": "3.0.3599",
        }
    },
    "aspnetcore50": {}
}

Then you might have to either use some conditional blocks in your code (#if ASPNET50) or remove CoreCLR all together.



来源:https://stackoverflow.com/questions/28423123/problems-with-ravendb-client-reference-in-asp-net-5-0-project-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!