简体   繁体   English

使用Visual Studio 2015无法解析.NET Core 1.1中的项目

[英]Cannot resolve a project in .NET Core 1.1 using Visual Studio 2015

I have a VS 2015 (Ver 14 Update 3, latest .NET Core tooling installed) solution which contains several class libraries and a executable project. 我有一个VS 2015(Ver 14 Update 3,安装了最新的.NET Core工具)解决方案,其中包含几个类库和一个可执行项目。 I am using ASP.NET Core 1.1. 我正在使用ASP.NET Core 1.1。 The problem is that despite right clicking on the "Resources" of the client program and ensuring that the library project is checked/included, and despite the library project being listed as a dependency in the Project.json file (and restored of course), VS is still telling me that it cannot resolve the namespace/classes from the class library project. 问题是,尽管右键单击客户端程序的“资源”并确保已检查/包含库项目,并且尽管库项目在Project.json文件中被列为依赖项(当然也已还原), VS仍然告诉我它无法从类库项目中解析名称空间/类。 Sometimes it even builds, other times it won't, but my code is littered with red and when I hit alt+enter, ReSharper gives me the option to add usings and references, and when it does this, everything is still red and cannot be located. 有时它甚至可以构建,而其他时候却不能,但是我的代码上乱七八糟,当我按下alt + enter时,ReSharper为我提供了添加使用和引用的选项,当这样做时,一切仍然是红色并且不能位于。

Is there anything aside from the Resources, project.json, and using statements that I need to handle in ASP.NET Core to include a class library properly? 除了Resources,project.json以及使用我需要在ASP.NET Core中处理的语句以正确包含类库之外,还有什么吗? Thanks. 谢谢。

PS: I also tried importing the DLL assembly but it said I could only import .NET Framework assemblies in the project, so that failed as well. PS:我也尝试导入DLL程序集,但是它说我只能在项目中导入.NET Framework程序集,因此也失败了。 Also, my colleague is not having this problem on his machine with the same tooling. 同样, 我的同事在使用相同工具的机器上也没有这个问题。

Project.json : Project.json

    {
  "dependencies": {
    "Churnite.Data": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.1.0",
    "Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": {
      "type": "build",
      "version": "1.1.0-preview4-final"
    },
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Churnite.Domain": "1.0.0-*",
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
  },

  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ],
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      }
    }
    },
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },
  "runtimes": {
    "win10-x64": {}
  }
}

Note: Churnite.Data is the project that is not working. 注意:Churnite.Data是无法正常工作的项目。 the "Data" portion is what VS is saying that it cannot locate. VS说“无法找到”是“数据”部分。

your should update the references in your project.json file for netcoreapp1.0 or Microsoft.NetCore.App version 1.0 to version 1.1 您应该将project.json文件中对netcoreapp1.0Microsoft.NetCore.App版本1.0的引用更新为版本1.1

在此处输入图片说明 update an existing project to ASP.NET Core 1.1 将现有项目更新为ASP.NET Core 1.1

You could be done some changes in project.json: 您可以在project.json中进行一些更改:

  1. Microsoft.NETCore.App to Microsoft.NETCore.App

    "Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" } “ Microsoft.NETCore.App”:{“版本”:“ 1.1.0”,“类型”:“平台”}

  2. frameworks to 框架

    "frameworks": { "netcoreapp1.1": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } } “ frameworks”:{“ netcoreapp1.1”:{“ imports”:[“ dotnet5.6”,“ portable-net45 + win8”]}}

Hope this help! 希望对您有所帮助!

In .Net Core 1.1 project.json has been retired in favour of an MSBuild compatible csproj file. 在对.NET核心1.1 project.json已经退休有利于一个MSBuild兼容的csproj文件。 So you can edit the .csproj file to use .Net 4.6 (or other version) 因此,您可以编辑.csproj文件以使用.Net 4.6(或其他版本)

Instead of: 代替:

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

Set: 组:

  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
  </PropertyGroup>

Now you can reference a project, like a library in .Net 4.6 现在您可以引用一个项目,例如.Net 4.6中的库

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM