Skip to content

Commit 3e1ff87

Browse files
authored
Merge pull request #8031 from sailro/patch-27
Update troubleshooting steps for Visual Studio Tools for Unity
2 parents 4fdc3bb + da10659 commit 3e1ff87

7 files changed

+61
-116
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57563,6 +57563,11 @@
5756357563
"source_path": "mac/extending-visual-studio-mac.md",
5756457564
"redirect_url": "/visualstudio/mac/customizing-the-ide",
5756557565
"redirect_document_id": false
57566+
},
57567+
{
57568+
"source_path": "gamedev/unity/extensibility/share-the-unity-log-callback-with-vstu.md",
57569+
"redirect_url": "/visualstudio/gamedev/unity/extensibility/programming-visual-studio-tools-for-unity",
57570+
"redirect_document_id": false
5756657571
}
5756757572
]
5756857573
}

gamedev/toc.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
items:
1919
- name: Customizing project file generation
2020
href: unity/extensibility/customize-project-files-created-by-vstu.md
21-
- name: Log callbacks
22-
href: unity/extensibility/share-the-unity-log-callback-with-vstu.md
2321
- name: Tools for Unity changelogs
2422
items:
2523
- name: Visual Studio
2624
href: unity/change-log-visual-studio-tools-for-unity.md
2725
- name: Visual Studio for Mac
28-
href: unity/change-log-visual-studio-tools-for-unity-mac.md
26+
href: unity/change-log-visual-studio-tools-for-unity-mac.md

gamedev/unity/change-log-visual-studio-tools-for-unity.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,9 +1873,9 @@ Released November 28, 2012
18731873

18741874
- Parsing of Info console message, so that clicking in the Error List take you to the first stackframe with symbols.
18751875

1876-
- Add an [API](extensibility/customize-project-files-created-by-vstu.md) to let user participate in the project generation.
1876+
- Add an API to let user participate in the project generation.
18771877

1878-
- Add an [API](extensibility/share-the-unity-log-callback-with-vstu.md) to let user participate in the LogCallback.
1878+
- Add an API to let user participate in the LogCallback.
18791879

18801880
### Bug fixes
18811881

gamedev/unity/extensibility/customize-project-files-created-by-vstu.md

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Customize Project Files Created by VSTU | Microsoft Docs"
33
description: Learn to customize project files created by Visual Studio Tools for Unity (VSTU). Review a C# code example.
44
ms.custom: ""
5-
ms.date: "07/26/2018"
5+
ms.date: "04/19/2021"
66
ms.technology: vs-unity-tools
77
ms.prod: visual-studio-dev16
88
ms.topic: "conceptual"
@@ -14,56 +14,30 @@ ms.workload:
1414
- "unity"
1515
---
1616
# Customize project files created by VSTU
17-
Visual Studio Tools for Unity provides a Unity-style callback during project file generation. Register with the `VisualStudioIntegration.ProjectFileGeneration` event to modify the project file whenever it's regenerated.
17+
Unity provides callbacks during project file generation. Implement `OnGeneratedSlnSolution` and `OnGeneratedCSProject` methods using an [`AssetPostprocessor`](https://docs.unity3d.com/ScriptReference/AssetPostprocessor.html) to modify the project or solution file whenever it's regenerated.
1818

1919
## Demonstrates
20-
How to customize the Visual Studio project files generated by Visual Studio Tools for Unity.
20+
How to customize the Visual Studio project files generated by Visual Studio Tools for Unity.
2121

2222
## Example
2323

2424
```csharp
25-
#if ENABLE_VSTU
2625
using System;
27-
using System.IO;
28-
using System.Linq;
29-
using System.Text;
30-
using System.Xml.Linq;
31-
32-
using UnityEngine;
3326
using UnityEditor;
27+
using UnityEngine;
3428

35-
using SyntaxTree.VisualStudio.Unity.Bridge;
36-
37-
[InitializeOnLoad]
38-
public class ProjectFileHook
29+
public class ProjectFilePostprocessor : AssetPostprocessor
3930
{
40-
// necessary for XLinq to save the xml project file in utf8
41-
class Utf8StringWriter : StringWriter
42-
{
43-
public override Encoding Encoding
44-
{
45-
get { return Encoding.UTF8; }
46-
}
47-
}
48-
49-
static ProjectFileHook()
50-
{
51-
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
52-
{
53-
// parse the document and make some changes
54-
var document = XDocument.Parse(content);
55-
document.Root.Add(new XComment("FIX ME"));
56-
57-
// save the changes using the Utf8StringWriter
58-
var str = new Utf8StringWriter();
59-
document.Save(str);
60-
61-
return str.ToString();
62-
};
63-
}
31+
public static string OnGeneratedSlnSolution(string path, string content)
32+
{
33+
// TODO: process solution content
34+
return content;
35+
}
36+
37+
public static string OnGeneratedCSProject(string path, string content)
38+
{
39+
// TODO: process project content
40+
return content;
41+
}
6442
}
65-
#endif
6643
```
67-
68-
## See also
69-
[Example: Log callback](/cross-platform/share-the-unity-log-callback-with-vstu.md)

gamedev/unity/extensibility/programming-visual-studio-tools-for-unity.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: "Programming Visual Studio Tools for Unity | Microsoft Docs"
3-
description: See examples of programming using the Visual Studio Tools for Unity (VSTU) API. Customize project files created by VSTU. Share the Unity log callback with VSTU.
3+
description: See examples of programming using the Visual Studio Tools for Unity (VSTU) API. Customize project files created by VSTU.
44
ms.custom: ""
5-
ms.date: "11/04/2016"
5+
ms.date: "04/19/2021"
66
ms.technology: vs-unity-tools
77
ms.prod: visual-studio-dev16
88
ms.topic: "conceptual"
@@ -20,7 +20,4 @@ In this section, you'll find examples for using the Visual Studio Tools for Unit
2020
Here are some examples that show how you can use the Visual Studio Tools for Unity APIs.
2121

2222
### Customize project files created by VSTU
23-
Visual Studio Tools for Unity provides a Unity-style callback during project file generation. To learn how you can modify the project file whenever it's regenerated, see [Example: Project file generation](./customize-project-files-created-by-vstu.md).
24-
25-
### Share the Unity log callback with VSTU
26-
Visual Studio Tools for Unity registers a log callback with Unity to be able to stream its console to Visual Studio. If your editor scripts also register a log callback with Unity, the VSTU callback might interfere with it. To learn how you can share the Unity log callback with VSTU, see [Example: Log callback](./share-the-unity-log-callback-with-vstu.md).
23+
Unity provides callbacks during project file generation. To learn how you can modify project or solution files whenever it's regenerated, see [Example: Project file generation](./customize-project-files-created-by-vstu.md).

gamedev/unity/extensibility/share-the-unity-log-callback-with-vstu.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

gamedev/unity/troubleshooting/troubleshooting-and-known-issues-visual-studio-tools-for-unity.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Troubleshooting and known issues (VS Tools for Unity)"
33
description: Read about troubleshooting in Visual Studio Tools for Unity. See descriptions of known issues, and learn about solutions to those issues.
44
ms.custom: ""
5-
ms.date: "07/03/2018"
5+
ms.date: "04/15/2021"
66
ms.technology: vs-unity-tools
77
ms.prod: visual-studio-dev16
88
ms.topic: troubleshooting
@@ -19,9 +19,15 @@ In this section, you'll find solutions to common issues with Visual Studio Tools
1919

2020
## Troubleshooting the connection between Unity and Visual Studio
2121

22-
### Confirm Editor Attaching is enabled
22+
### Confirm `Editor Attaching` is enabled or `Code Optimization On Startup` is set to `Debug`
2323

24-
In the Unity Menu, select **Edit > Preferences** and then select the **External Tools** tab. Confirm that the **Editor Attaching** checkbox is enabled. For more information, see the [Unity Preferences documentation](https://docs.unity3d.com/Manual/Preferences.html).
24+
In the Unity Menu, select `Edit / Preferences`.
25+
26+
Depending on the Unity version used :
27+
- Confirm that `Code Optimization On Startup` is set to `Debug`.
28+
- Or select the `External Tools` tab. Confirm that the `Editor Attaching` checkbox is enabled.
29+
30+
For more information, see the [Unity Preferences documentation](https://docs.unity3d.com/Manual/Preferences.html).
2531

2632
### Unable to attach
2733

@@ -54,11 +60,22 @@ For FMOD, there is a workaround, you can pass `FMOD_STUDIO_INIT_SYNCHRONOUS_UPDA
5460

5561
## Incompatible project in Visual Studio
5662

57-
First, check that Visual Studio is set as your external script editor in Unity (Edit/Preferences/External Tools). Then check that the Visual Studio plugin is installed in Unity (Help/About must display a message like Microsoft Visual Studio Tools for Unity is enabled at the bottom). Then check that the extension is properly installed in Visual Studio (Help/About).
63+
The very important thing to know is that Visual Studio is saving the “Incompatible” state in project settings and will not try to reload a project until you explicitly use `Reload Project`. So, after each troubleshooting step, make sure you try to re-open the solution and try to right-click on all incompatible projects and choose `Reload Project`.
64+
65+
1. Check that Visual Studio is set as your external script editor in Unity using `Edit / Preferences / External Tools`.
66+
2. Depending on your Unity version:
67+
- Check that the Visual Studio plugin is installed in Unity. `Help / About` should display a message like Microsoft Visual Studio Tools for Unity is enabled at the bottom.
68+
- Unity 2020.x+: Check that you are using the latest Visual Studio Editor package in `Window / Package Manager`.
69+
3. Try deleting all projects/solution files and the `.vs` folder in your project.
70+
4. Try recreating projects/solution using `Open C# Project` or `Edit / Preferences / External tools / Regenerate Project files`.
71+
5. Make sure you installed the Game/Unity workload in Visual Studio.
72+
6. Try to clean the MEF cache as explained [here](#visual-studio-crashes).
73+
7. Try to re-install Visual Studio (using the Game/Unity workload only to start).
74+
8. Try to disable third-party extensions in case they could interfere with the Unity extension in `Tools / Extensions`.
5875

5976
## Extra reloads, or Visual Studio losing all open windows
6077

61-
Be sure to never touch project files directly from an asset processor or any other tool. If you really need to manipulate the project file, we expose an API for that. Please check the [Assembly references issues section](#assembly-reference-issues).
78+
Be sure to never touch project files directly from an asset processor or any other tool. If you really need to manipulate the project file, we expose an API for that. Please check the [Assembly references issues section](#assembly-reference-or-project-property-issues).
6279

6380
If you experience extra reloads or if Visual Studio is losing all open Windows on reload, make sure that you have proper .NET targeting packs installed. Check the following section about frameworks for more information.
6481

@@ -72,21 +89,23 @@ In the Exception Settings window (Debug > Windows > Exception Settings), expand
7289

7390
## On Windows, Visual Studio asks to download the Unity target framework
7491

75-
Visual Studio Tools for Unity requires the .NET framework 3.5, which isn't installed by default on Windows 8 or 10. To fix this issue, follow the instructions to download and install the .NET framework 3.5.
92+
When using the legacy Unity runtime (.NET 3.5 equivalent), Visual Studio Tools for Unity requires the .NET framework 3.5, which isn't installed by default on Windows 8 or 10. To fix this issue, follow the instructions to download and install the .NET framework 3.5.
93+
94+
When using the new Unity runtime, .NET targeting packs version 4.6 or 4.7.1 are also required depending on the Unity version. It is possible to use the Visual Studio installer to quickly install them (modify your installation, individual components, .NET category, select all 4.x targeting packs).
7695

77-
When using the new Unity runtime, .NET targeting packs version 4.6 and 4.7.1 are also required. It is possible to use the VS2017 installer to quickly install them (modify your VS2017 installation, individual components, .NET category, select all 4.x targeting packs).
96+
## Assembly reference or project property issues
7897

79-
## Assembly reference issues
98+
If your project is complex reference-wise or if you want to better control this generation step, you can use our [API](../extensibility/customize-project-files-created-by-vstu.md) for manipulating the generated project or solution content. You can also use [response files](https://docs.unity3d.com/Manual/PlatformDependentCompilation.html) in your Unity project and we'll process them.
8099

81-
If your project is complex reference-wise or if you want to better control this generation step, you can use our [API](/cross-platform/customize-project-files-created-by-vstu.md) for manipulating the generated project or solution content. You can also use [response files](https://docs.unity3d.com/Manual/PlatformDependentCompilation.html) in your Unity project and we'll process them.
100+
With recent Visual Studio and Unity versions, the best approach seems to use a custom `Directory.Build.props` file along with your generated projects. You will then be able to contribute to the project structure without interfering with the generation process. More information [here](https://docs.microsoft.com/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets).
82101

83102
## Breakpoints with a warning
84103

85104
If Visual Studio is unable to find a source location for a specific breakpoint you will see a warning around your breakpoint. Check that the script you are using is properly loaded/used in the current Unity scene.
86105

87106
## Breakpoints not hit
88107

89-
Check that the script you are using is properly loaded/used in the current Unity scene. Quit both Visual Studio and Unity then delete all generated files (\*.csproj, \*.sln) and the whole Library folder.
108+
Check that the script you are using is properly loaded/used in the current Unity scene. Quit both Visual Studio and Unity then delete all generated files (\*.csproj, \*.sln), the `.vs` folder and the whole Library folder. You can find more information on C# debugging on the Unity [website](https://docs.unity3d.com/Manual/ManagedCodeDebugging.html).
90109

91110
## Unable to debug Android players
92111

@@ -96,13 +115,13 @@ Wifi is versatile but super slow compared to USB because of latency. We saw a la
96115

97116
USB is super-fast for debugging, and Visual Studio Tools for Unity is now able to detect USB devices, and talk to the adb server to properly forward ports for debugging.
98117

99-
## Issues with Visual Studio 2015 and IntelliSense or code coloration
118+
## Issues with IntelliSense or code coloration
100119

101-
Try upgrading your Visual Studio 2015 to update 3.
120+
Try upgrading your Visual Studio to the latest version. Try the same same troubleshooting steps as for [Incompatible projects](#incompatible-project-in-visual-studio).
102121

103122
## Known issues
104123

105-
There are known issues in Visual Studio Tools for Unity that result from how the debugger interacts with Unity's older version of the C# compiler. We're working to help fix these problems, but you might experience the following issues in the meantime:
124+
There are known issues in Visual Studio Tools for Unity that result from how the debugger interacts with Unity's older version of the C# compiler. We're working to help fix these problems, but you might experience the following issues in the meantime:
106125

107126
- When debugging, Unity sometimes crashes.
108127

@@ -112,11 +131,11 @@ Try upgrading your Visual Studio 2015 to update 3.
112131

113132
## Report errors
114133

115-
Please help us improve the quality of Visual Studio Tools for Unity by sending error reports when you experience crashing, freezes, or other errors. This helps us investigate and fix problems in Visual Studio Tools for Unity. Thank you!
134+
Please help us improve the quality of Visual Studio Tools for Unity by sending error reports when you experience crashing, freezes, or other errors. This helps us investigate and fix problems in Visual Studio Tools for Unity. Thank you!
116135

117136
### How to report an error when Visual Studio freezes
118137

119-
There are reports that Visual Studio sometimes freezes when debugging with Visual Studio Tools for Unity, but we need more data to understand this problem. You can help us investigate by following the steps below.
138+
There are reports that Visual Studio sometimes freezes when debugging with Visual Studio Tools for Unity, but we need more data to understand this problem. You can help us investigate by following the steps below.
120139

121140
##### To report that Visual Studio freezes while debugging with Visual Studio Tools for Unity
122141

0 commit comments

Comments
 (0)