aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 124 forks source link

Referencing multi-framework project from another project breaks intellisense but still compiles #874

Open EvK opened 7 years ago

EvK commented 7 years ago

Using Visual Studio 2015 Update 3 with NET Core 1.0.1 tools Preview 2.

To reproduce:

Create Class Library (.NET Core) project with the following project.json and name it "NetCore"

{
  "version": "1.0.0-*",

  "frameworks": {
    "netstandard1.0": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    },
    "net40": {},
    "net45": {}
  }
}

Create test class as follows:

namespace NetCore
{
#if NETSTANDARD1_0
    public class ClassNetStandard { }
#endif

#if NET40
    public class ClassNet40 { }
#endif

#if NET45
    public class ClassNet45 { }
#endif
}

Create Console Application (.NET Core) with the following project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "NetCore": { "target": "project" }
  },
  "frameworks": {
    "net451": {}
  }
}

Create the following class:

namespace CoreConsole
{
    public class Program
    {
        public static void Main(string[] args) {
            new NetCore.ClassNet45();
        }
    }
}

Now try to build. Visual Studio will output the following error (and will underline ClassNet45 with red squiggle line)

Error CS0234 The type or namespace name 'ClassNet45' does not exist in the namespace 'NetCore' (are you missing an assembly reference?)

But in output you will see that project successfully compiled, and you can see compiled dll on hard drive.

If you will put "net45" framework first in the list in project.json of NetCore project, like this

{
  "version": "1.0.0-*",

  "frameworks": {
    "net45": {},
    "netstandard1.0": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    },
    "net40": {}
  }
}

Then no error will be produced by Visual Studio.