[Bug] Unity 2020.1: ENABLE_VSTU define is gone and ProjectFileGeneration event isn't raised anymore.

EDIT: Added the 2nd bug report related to this one.

2 bugs in Unity 2020.1: ENABLE_VSTU define is gone and ProjectFilesGenerator.ProjectFileGeneration event isn’t raised anymore.

Bug report: https://fogbugz.unity3d.com/default.asp?1267165_ro5g3ugjh2brhlo5
Bug report 2: https://fogbugz.unity3d.com/default.asp?1270064_58kkt7lqmq68j9uf
Issue Tracker:
Unity Issue Tracker - ENABLE_VSTU define is missing
Unity Issue Tracker - ProjectFilesGenerator.ProjectFileGeneration event isn't raised

As can be seen in the second bug report, the
Editor Attaching option is gone in Unity 2020.1. Visual Studio Tools For Unity documentation specifically states that “Editor Attaching” must be enabled but that option is gone in 2020.1.


Related script file is attached below (Must be in a Editor folder).

After upgrading my project to Unity 2020.1, I experience 2 serious problems.

Bug 1) ProjectFilesGenerator.ProjectFileGeneration event isn’t raised when Unity generates the VS project files anymore so I can’t modify the VS project files in an automated way. ProjectFilesGenerator class is part of SyntaxTree.VisualStudio.Unity.Bridge namespace which is provided by “Visual Studio Unity Tools” plugin (a VS plugin; not a Unity plugin) and Unity VS integration adds a reference to that namespace automaticaly. Unity 2020 still adds the reference correctly but for some reason, ProjectFilesGenerator class doesn’t work correctly on Unity 2020.

Bug 2) We were able to detect if “Visual Studio Unity Tools” plugin was present on the computer by checking the ENABLE_VSTU define in an editor script but in Unity 2020.1 that compiler define is gone so we can’t detect if VSTU is present or not.

I know that VS integration was moved from Unity core to a Unity package in Unity 2020.1 but somehow we should be able to use ProjectFilesGenerator.ProjectFileGeneration event on Unity 2020.1 too.

Repro steps:

  1. Make sure Visual Studio 2019 and its “Visual Studio Unity Tools” plugin is installed on a Windows computer along with Unity 2020.1.
  2. Open my Unity project and see the SuppressCompilerWarnings script in the Editor folder.
  3. Open the C# project in VS via Unity’s Assets menu.
  4. Go to the SuppressCompilerWarnings.cs file.
  5. See that the entire code part inside of #if ENABLE_VSTU block is disabled because ENABLE_VSTU is not defined in Unity C# project anymore. This is the first bug.
  6. Manually delete these lines below and save the file. This way the code block will be enabled:
    a) #if ENABLE_VSTU
    b) #endif
  7. Notice that there is a debug line in ProjectFileGeneration event handler which prints “ProjectFileGeneration” to the console.
  8. Go to Unity.
  9. Open Unity Preferences via Edit menu.
  10. Go to External Tools tab.
  11. Click the “Regenerate project files” button.
  12. Notice that “ProjectFileGeneration” debug log enrty isn’t printed to console because ProjectFilesGenerator.ProjectFileGeneration event isn’t raised anymore. This is the second and more important bug.

6153130–672307–SuppressCompilerWarnings.cs (1.23 KB)

Unity QA reported that these bugs are caused by VSTU and I should contact to Microsoft for this but I don’t agree with that because I didn’t update my VS or VSTU. I just upgraded Unity to 2020.1 and this problem started to happen.

Also, VSTU documentation specifically states that “Editor Attaching” must be enabled but that option is gone in Unity 2020.1. I think this is a missing feature in the new Visual Studio Editor package from Unity.

I reported this to Unity as a new bug: https://fogbugz.unity3d.com/default.asp?1270064_58kkt7lqmq68j9uf

Unity QA replied:
The ‘Editor Attaching’ option has been moved to the lower-right corner of the Editor window as the ‘Debugger’ (‘Bug/Insect’ Icon) option.

I am not 100% sure that the Editor Attaching and the Debugger Attaching are the same thing. I asked Unity QA to confirm this. Probably I’mm report the bug to Microsoft soon.

I sent and email to vstusp@microsoft.com describing the problem.

@Xtro

Sorry for the confusion!

Starting with Unity 2020 versions, the integration with external code editors needed to be moved to a Unity Package. We worked with Unity to migrate the existing integration between the Unity Editor and Visual Studio tooling to a package which is automatically added to Unity 2020 projects. Therefore, you experienced differences when only updating Unity because of that change.

Fortunately, there is a straightforward migration path for the project file generation - which is a breaking change that we will document. In the meantime, you can use an AssetPostProcessor like this:

public class ProjectFilePostprocessor : AssetPostprocessor
{
        public static string OnGeneratedSlnSolution(string path, string content)
        {
            return content;
        }

        public static string OnGeneratedCSProject(string path, string content)
        {
            return content;
        }
}

The ENABLE_VSTU is no longer needed with this new way.

If you’re only suppressing CS0649, you don’t need to do that anymore. In Visual Studio 16.4 and higher, we included new Unity-specific Roslyn diagnostic suppressors and analyzers. There is a suppressor already included in VSTU to silence that message for Unity scenarios. More info here: Microsoft.Unity.Analyzers/doc/USP0007.md at main · microsoft/Microsoft.Unity.Analyzers · GitHub

If there are more diagnostics or suppressors, we’d love to learn about them on that GitHub project - file a new issue using the template.

With regards to the Editor Attaching option missing, that’s a change Unity 2020 versions too. The debugging workflow changed to improve performance outside of debugging scenarios. You now have to opt-in to a debug mode in the Unity Editor using the Debug icon in the lower right. Alternatively, Unity should prompt you to enable or disable that setting if you try to attach Visual Studio while the Unity Editor is in release mode. I will update the VSTU documentation for this.

Mention of the VS Package and Debugging workflow changes here for more context: Unity Blog

1 Like

Thank you very much.

It’s nice to see your personal reply in here instead of using issue tracker portals.

@John_MSFT

Oh, OK. I get it now. Earlier, I noticed that ENABLE_VSTU was missing because I started to get CS0649 warnings in VS but now, after your explanation, I checked those warnings again and they are not coming from fields marked as
[SerializeField]. They are actually coming from fields marked as [AutoLink] which totally my custom attribute.

Until now, I was suppressing CS0649 globally but now since you are suppressing it only for specific attributes, I have this problem.

I don’t know anything about Roslyn diagnostic suppressors and analyzers.

Is it possible for me to implement my custom CS0649 suppressors for my custom Attributes?

@Xtro

You can use the new way to hook into the project file generation shown above and add <NoWarn>0649</NoWarn> to a PropertyGroup.

You could instead create your own custom suppressor for this, but it’s a little heavy handed for a single warning ignore. You could take inspiration from the existing suppressors: Microsoft.Unity.Analyzers/src/Microsoft.Unity.Analyzers/SerializeFieldSuppressor.cs at main · microsoft/Microsoft.Unity.Analyzers · GitHub

Thank you John. I’ll check that.

1 Like

Found this topic on my research why my script to include the .editorConfig in the solution suddenly no longer works.

Here’s a fix for the lost souls like me

Tags: .editorconfig, Solution, ENABLE_VSTU, InitializeOnLoad

@Xtro @CortiWins

Good news! You don’t have to use an AssetPostProcessor for things like .editorConfig since version 4.7.0.0 of the Visual Studio Tools for Unity (Unity 2019) or the 2.0.2 version of the Visual Studio Editor package in Unity 2020.

These types of solution items are persisted automatically now.

1 Like