Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch context in VS.NET 2015?

I'm getting build errors because some classes I'm using are available in "DNX 4.5.1" and not "DNX Core 5.0".

The error is:

The type or namespace '[someclass]' could not be found.

In the project column of the "Error List" window, I see DNX Core 5.0.

In the context menu, DNX 4.5.1 is selected. Why does VS.NET try to keep using DNX Core 5.0 when the context is 4.5.1?

like image 747
4thSpace Avatar asked May 06 '15 20:05

4thSpace


2 Answers

In case some people are still struggling with this, you can dereference the DNX Core 5.0 by removing it from your framework references in the project.json file.

The section

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

Should become

  "frameworks": {
    "dnx451": { }
  },
like image 115
BasiK Avatar answered Oct 25 '22 21:10

BasiK


Rather than completely removing DNXCORE50 from your project.json. As before, you can add framework specific code if you wrap it in #if #endif as shown in the code below. The framework names DNX451 and DNXCORE50 are well known symbols actually referred to as target framework monikers (TFMs) and are the same throughout the project.json file, folder names, NuGet packages etc.

Simply apply a conditional statement:

public string Index(){
   #if DNX451
      //code logic here for DNX 4.5.1
   #endif
   #if DNXCORE50

      //code logic here for DNX Core 5.0

   #endif
}
like image 36
Ifeanyi Chukwu Avatar answered Oct 25 '22 20:10

Ifeanyi Chukwu