Tom
Tom

Reputation: 336

Can I test/run Unity C# in Visual Studio/Code?

I'm working on a Unity project and want to test/try some code: i.e. loading a CSV and save in a different Dictionaries. As for now, I'm coding in Visual Studio/Code and have to switch back to Unity to run it.

Is there a way to test run the code in the Visual Studio/Code directly - only for console output? This would be great for testing, instead of switching back and forward all the time.

Thanks

Upvotes: 3

Views: 1513

Answers (1)

Blindleistung
Blindleistung

Reputation: 702

For a game project of mine, I set up a seperate VS project independent from the Unity project, and bound all the cs files in there.

The files tested this way did not use UnityEngine at all, but you could also set up a dummy-UnityEngine for the test. Location of this folder is outside of the Unity project folder to prevent Unity from touching those test cs files and vcproj files.

From the VS project, I can simply include any cs files from the Unity-project Assets folder.

My dir structure:

ProjectRoot/  <== real project root folder.
    .git/    <== git tracking for unity part and testcode.
    Unity/   <==  Unity's project homedirectory.
        Assets/
            script
                ... various scripts.
        mats/
        scenes/
        .....     <==  lots of Unity project stuff
    testcode.sln
    testcode.vcproj  <== refers to cs files from testcode AND Unity.
    testcode/
        testclass.cs
        .....

For testing, I open the testcode.sln in VS, and compile-and-run it all in there. Unity need not be open.

Upvotes: 3

Related Questions