Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Visual Studio Code and using defined symbols

EDIT: I have edited the whole question, since this is not only for Unity3D, but at all .sln projects.

I have a installation of Visual Studio Code(Not Visual Studio, but this:https://code.visualstudio.com/) on my Macbook at work. VSCode is otherwise working just fine with normal and Unity3D projects. I get Intellisense on all classes, including Unity3D specific ones, like GameObject. So I think my installation and startup sequence is correct.

Only problem I have, is that VSCode does not seem to recognize constants defined in the .csproj files. First I noticed this with some Unity3D plugins, but it is persistent on normal Visual Studio projects too.

My sample project is a dummy application downloaded from internet, but it is fully working on MonoDevelop. This is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DummyConsoleApplication
    {
    class Program
        {
            static void Main(string[] args)
            {
                tester();
            }

            #if DEBUG
            static void tester(){

            }
            #endif
        }
    }

The function call in Main causes a not found exception on the editor, but it compiles fine, since the .csproj file has this line:

<DefineConstants>DEBUG;TRACE</DefineConstants>

Any verification on if this is normal behaviour for VSCode would be greately appreciated. Also, if anyone is aware of any solution, even hacky ones, to get past this bug and force Intellisense to autocomplete would help out too.

The error I get is:

The name 'tester' does not exist in the current context [DummyConsoleApplication]

My hardware is a Macbook with Yosemite and my compiler is dnx-mono.1.0.0-beta4.

like image 835
Quido3 Avatar asked May 18 '15 07:05

Quido3


People also ask

How do you use symbol in VS Code?

We can navigate to a symbol inside this file using Command + Shift + O (Mac) or Ctrl + Shift + O (Windows). That's an O as in orange! When we use this keyboard shortcut within VS Code, the Command Palette will open and insert an @ character. This means we're ready to navigate using symbols!

How do you show special characters in VS Code?

In Visual Studio Code's menu bar, go to Code › Preferences › Settings or press ⌘ + , . Search for Render Whitespace (in the Search settings search bar). Set the value to all .

How do I enable definition in Visual Studio?

Go To Definition If you are a keyboard user, place your text cursor somewhere inside the symbol name and press F12. If you are a mouse user, either select Go To Definition from the right-click menu or use the Ctrl-click functionality described in the following section.

Why is definition disabled in Visual Studio?

Answers. Don't close Visual Studio but close all the files and open them again by clicking on the file in the solution. The file might have been opened by Source Safe or you maybe opened it from Windows Explorer. In this case the file doesn't get assosiated with your solution and the Go to Def.


1 Answers

This is a known limitation with OmniSharp, the C# engine that Visual Studio Code is built around. There is an open enhancement request for adding <DefineConstants> support, but it is tied to a larger issue with regards to MSBuild Support.

Currently, this isn't a supported configuration under Visual Studio Code. You can try to define your constants through the launch.json instead, but support is minimal at best.

like image 59
Claies Avatar answered Sep 24 '22 00:09

Claies