Using Visual Studio Code and using defined symbols

落花浮王杯 提交于 2021-02-07 06:16:06

问题


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.


回答1:


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.




回答2:


It should work...

As a sanity check, have you:

  • "Sync MonoDevelop Project" recently?
  • Make sure Visual Studio Code has the -csharp solution (.sln) selected? (Click the flame in the status bar to change)


来源:https://stackoverflow.com/questions/30297666/using-visual-studio-code-and-using-defined-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!