Using Visual Studio Code and Using Specific Symbols

EDIT: I edited the whole question, as this applies not only to Unity3D, but all .sln projects as well.

I have a Visual Studio code installation (not Visual Studio, but this: https://code.visualstudio.com/ ) on my Macbook at work. VSCode otherwise works fine with regular and Unity3D projects. I get Intellisense for all classes, including Unity3D, such as GameObject. Therefore, I believe that my installation and startup sequence are correct.

The only problem I have is that VSCode does not seem to recognize the constants defined in the .csproj files. At first I noticed this with some Unity3D plugins, but it is also saved in regular Visual Studio projects.

My sample project is a dummy application downloaded from the Internet, but it works completely 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 } } 

A function call in Main raises an exception not found in the editor, but it compiles fine, because the .csproj file has the following line:

 <DefineConstants>DEBUG;TRACE</DefineConstants> 

Any verification, if this is normal behavior for VSCode, would be greatly appreciated. In addition, if anyone knows of any solution, even hacking, to get past this error and force Intellisense to autofill will also help.

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.

+8
c # constants csproj visual-studio-code
source share
2 answers

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

This is currently not a supported configuration in Visual Studio Code. You can try to define your constants using launch.json , but support is minimal at best.

+3
source share

It should work ...

As a health check, you have:

  • "Sync MonoDevelop Project" recently?
  • Verify that Visual Studio Code has the -csharp (.sln) solution? (Click the flame in the status bar to change)
+3
source share

All Articles