简体   繁体   中英

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. I am using 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. 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.

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? 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. Also, my colleague is not having this problem on his machine with the same tooling.

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. the "Data" portion is what VS is saying that it cannot locate.

your should update the references in your project.json file for netcoreapp1.0 or Microsoft.NetCore.App version 1.0 to version 1.1

在此处输入图片说明 update an existing project to ASP.NET Core 1.1

You could be done some changes in project.json:

  1. Microsoft.NETCore.App to

    "Microsoft.NETCore.App": { "version": "1.1.0", "type": "platform" }

  2. frameworks to

    "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. So you can edit the .csproj file to use .Net 4.6 (or other version)

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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