How to fix intellisense with referenced netstandar

2020-03-26 07:28发布

I have four library projects that are all targeting the netstandard1.5 framework. Some of them depend on the other and the intellisense is working fine under those four projects.

I am trying to use these libraries inside my ASP.NET netcoreapp1.0 project. But when I target the netcoreapp1.0 framework the types are not found (outlined red in visual studio). The project hower compiles and runs successfully.

As soon as I switch to the netstandard1.5 framework inside my web api the types of the libraries are recognized and I get intellisense.

Any ideas on how to fix this or what I am doing wrong?

Here is the project.json for one of the library projects (they are almost identical):

{
  "version": "1.0.0-*",

  "frameworks": {
    "netstandard1.5": {
      "imports": [ "dnxcore50", "portable-net45+win8" ],
      "dependencies": {
        "NETStandard.Library": "1.5.0-rc2-24027",

        "System.Security.Principal": "4.0.1-rc2-24027"
      }
    }
  },
  "dependencies": {
    "Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "HoehenSucht.Models": "1.0.0-*",
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027"
  }
}

And here is the project.json of the api:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "HoehenSucht.Framework": "1.0.0-*",
    "HoehenSucht.Models": "1.0.0-*",
    "HoehenSucht.Repositories": "1.0.0-*",
    "HoehenSucht.Services": "1.0.0-*",
    "HoehenSucht.Authentication": "1.0.0-*",
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Autofac.Extensions.DependencyInjection": "4.0.0-rc2-240",
    "AutoMapper": "4.2.1",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
    "System.Security.Principal": "4.0.1-rc2-24027",
    "System.Reflection": "4.1.0-rc2-24027",
    "IdentityServer4.AccessTokenValidation": "1.0.0-beta6",
    "Microsoft.AspNetCore.Authorization": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Hosting": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",
    "Autofac": "4.0.0-rc2-240",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "HoehenSucht.API.Models": "1.0.0-*",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "System.Linq": "4.1.0-rc2-24027",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "System.Linq.Parallel": "4.0.1-rc2-24027",
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0-*"
        },
        "System.Collections": "4.0.11-rc2-24027",
      },
      "imports": [ "dnxcore50", "portable-net45+win8" ]
    }
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  }
}

1条回答
我命由我不由天
2楼-- · 2020-03-26 07:59

Resharper is the problem here not Visual Studio.

http://blog.jetbrains.com/dotnet/2016/05/27/resharper-ultimate-2016-2-eap-kicks-off/

Initial support of ASP.NET Core 1.0 RC2, including support for tag helpers in terms of code completion, navigation, search and refactorings. At this point, ASP.NET Core web applications are supported if they’re targeting .NET Framework but are not supported if they’re targeting .NET Core. We’re looking to improve this in subsequent builds.

So if you have a library targeting .netstandard1.5 Resharper will not correctly display intellisense information but the project will compile.

However if you add the .netcoreapp1.0 framework as an additional framework to the project.json file Resharper will work and you get full intellisense support.

 frameworks": {
    "netstandard1.5": {
      "imports": [ "dnxcore50", "portable-net45+win8" ],
      "dependencies": {
        "NETStandard.Library": "1.5.0-rc2-24027",

        "System.Security.Principal": "4.0.1-rc2-24027"
      }
    },
    ".netcoreapp1.0": {
      "imports": [ "dnxcore50", "portable-net45+win8" ]
    }
 },
查看更多
登录 后发表回答