Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [2.0.2] - 2020-05-27

Added support for solution folders.
Only bind the messenger when the VS editor is selected.
Warn when unable to create the messenger.
Fixed an initialization issue triggering legacy code generation.
Allow package source in assembly to be generated when referenced from asmref.
  • Loading branch information
Unity Technologies committed May 27, 2020
1 parent ad189f9 commit fc2dc75
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 20 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Code Editor Package for Visual Studio

## [2.0.2] - 2020-05-27

Added support for solution folders.
Only bind the messenger when the VS editor is selected.
Warn when unable to create the messenger.
Fixed an initialization issue triggering legacy code generation.
Allow package source in assembly to be generated when referenced from asmref.


## [2.0.1] - 2020-03-19

When Visual Studio installation is compatible with C# 8.0, setup the language version to not prompt the user with unsupported constructs. (So far Unity only supports C# 7.3).
Expand Down
23 changes: 14 additions & 9 deletions Editor/ProjectGeneration/ProjectGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public class ProjectGeneration : IGenerator

const string k_WindowsNewline = "\r\n";

string m_SolutionProjectEntryTemplate = string.Join("\r\n",
@"Project(""{{{0}}}"") = ""{1}"", ""{2}"", ""{{{3}}}""",
@"EndProject").Replace(" ", "\t");
string m_SolutionProjectEntryTemplate = @"Project(""{{{0}}}"") = ""{1}"", ""{2}"", ""{{{3}}}""{4}EndProject";

string m_SolutionProjectConfigurationTemplate = string.Join("\r\n",
@" {{{0}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU",
Expand Down Expand Up @@ -87,6 +85,8 @@ public ProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNam
m_AssemblyNameProvider = assemblyNameProvider;
m_FileIOProvider = fileIoProvider;
m_GUIDGenerator = guidGenerator;

SetupProjectSupportedExtensions();
}

/// <summary>
Expand Down Expand Up @@ -412,7 +412,7 @@ string ProjectText(Assembly assembly,
projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
foreach (string file in assembly.sourceFiles)
{
if (!ShouldFileBePartOfSolution(file))
if (!IsSupportedFile(file))
continue;

var extension = Path.GetExtension(file).ToLower();
Expand Down Expand Up @@ -725,7 +725,7 @@ string SolutionText(IEnumerable<Assembly> assemblies, Solution previousSolution
const string vsversion = "15";

var relevantAssemblies = RelevantAssembliesForMode(assemblies);
var generatedProjects = ToProjectEntries(relevantAssemblies);
var generatedProjects = ToProjectEntries(relevantAssemblies).ToList();

SolutionProperties[] properties = null;

Expand All @@ -737,7 +737,7 @@ string SolutionText(IEnumerable<Assembly> assemblies, Solution previousSolution
{
// Add all projects that were previously in the solution and that are not generated by Unity, nor generated in the project root directory
var externalProjects = previousSolution.Projects
.Where(p => !FileUtility.IsFileInProjectDirectory(p.FileName))
.Where(p => p.IsSolutionFolderProjectFactory() || !FileUtility.IsFileInProjectDirectory(p.FileName))
.Where(p => generatedProjects.All(gp => gp.FileName != p.FileName));

projects.AddRange(externalProjects);
Expand All @@ -746,7 +746,11 @@ string SolutionText(IEnumerable<Assembly> assemblies, Solution previousSolution

string propertiesText = GetPropertiesText(properties);
string projectEntriesText = GetProjectEntriesText(projects);
string projectConfigurationsText = string.Join(k_WindowsNewline, projects.Select(p => GetProjectActiveConfigurations(p.ProjectGuid)).ToArray());

// do not generate configurations for SolutionFolders
var configurableProjects = projects.Where(p => !p.IsSolutionFolderProjectFactory());
string projectConfigurationsText = string.Join(k_WindowsNewline, configurableProjects.Select(p => GetProjectActiveConfigurations(p.ProjectGuid)).ToArray());

return string.Format(GetSolutionText(), fileversion, vsversion, projectEntriesText, projectConfigurationsText, propertiesText);
}

Expand Down Expand Up @@ -800,7 +804,7 @@ string GetProjectEntriesText(IEnumerable<SolutionProjectEntry> entries)
{
var projectEntries = entries.Select(entry => string.Format(
m_SolutionProjectEntryTemplate,
entry.ProjectFactoryGuid, entry.Name, entry.FileName, entry.ProjectGuid
entry.ProjectFactoryGuid, entry.Name, entry.FileName, entry.ProjectGuid, entry.Metadata
));

return string.Join(k_WindowsNewline, projectEntries.ToArray());
Expand All @@ -814,7 +818,8 @@ IEnumerable<SolutionProjectEntry> ToProjectEntries(IEnumerable<Assembly> assembl
ProjectFactoryGuid = SolutionGuid(assembly),
Name = assembly.name,
FileName = Path.GetFileName(ProjectFile(assembly)),
ProjectGuid = ProjectGuid(assembly)
ProjectGuid = ProjectGuid(assembly),
Metadata = k_WindowsNewline
};
}

Expand Down
5 changes: 3 additions & 2 deletions Editor/SolutionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
internal static class SolutionParser
{
// Compared to the bridge implementation, we are not returning "{" "}" from Guids
private static readonly Regex ProjectDeclaration = new Regex(@"Project\(\""{(?<projectFactoryGuid>.*?)}\""\)\s+=\s+\""(?<name>.*?)\"",\s+\""(?<fileName>.*?)\"",\s+\""{(?<projectGuid>.*?)}\""(?<content>.*?)\bEndProject\b", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
private static readonly Regex PropertiesDeclaration = new Regex(@"GlobalSection\((?<name>[\w]+Properties)\)\s+=\s+(?<type>(?:post|pre)Solution)(?<entries>.*?)EndGlobalSection", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
private static readonly Regex ProjectDeclaration = new Regex(@"Project\(\""{(?<projectFactoryGuid>.*?)}\""\)\s+=\s+\""(?<name>.*?)\"",\s+\""(?<fileName>.*?)\"",\s+\""{(?<projectGuid>.*?)}\""(?<metadata>.*?)\bEndProject\b", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
private static readonly Regex PropertiesDeclaration = new Regex(@"GlobalSection\((?<name>([\w]+Properties|NestedProjects))\)\s+=\s+(?<type>(?:post|pre)Solution)(?<entries>.*?)EndGlobalSection", RegexOptions.Singleline | RegexOptions.ExplicitCapture);
private static readonly Regex PropertiesEntryDeclaration = new Regex(@"^\s*(?<key>.*?)=(?<value>.*?)$", RegexOptions.Multiline | RegexOptions.ExplicitCapture);

public static Solution ParseSolutionFile(string filename, IFileIO fileIO)
Expand Down Expand Up @@ -42,6 +42,7 @@ private static SolutionProjectEntry[] ParseSolutionProjects(string content)
Name = match.Groups["name"].Value,
FileName = match.Groups["fileName"].Value,
ProjectGuid = match.Groups["projectGuid"].Value,
Metadata = match.Groups["metadata"].Value
});
}

Expand Down
8 changes: 8 additions & 0 deletions Editor/SolutionProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;

namespace Microsoft.Unity.VisualStudio.Editor
{
internal class SolutionProjectEntry
Expand All @@ -10,5 +12,11 @@ internal class SolutionProjectEntry
public string Name { get; set; }
public string FileName { get; set; }
public string ProjectGuid { get; set; }
public string Metadata { get; set; }

public bool IsSolutionFolderProjectFactory()
{
return ProjectFactoryGuid != null && ProjectFactoryGuid.Equals("2150E333-8FDC-42A3-9474-1A3956D46DE8", StringComparison.OrdinalIgnoreCase);
}
}
}
8 changes: 8 additions & 0 deletions Editor/VisualStudioEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ static VisualStudioEditor()
CodeEditor.Register(new VisualStudioEditor());
}

internal static bool IsEnabled
{
get
{
return CodeEditor.CurrentEditor is VisualStudioEditor;
}
}

public void CreateIfDoesntExist()
{
if (!_generator.HasSolutionBeenGenerated())
Expand Down
22 changes: 18 additions & 4 deletions Editor/VisualStudioIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using Microsoft.Unity.VisualStudio.Editor.Messaging;
using UnityEditor;
using UnityEngine;
Expand All @@ -21,14 +22,27 @@ internal class VisualStudioIntegration
private static readonly Queue<Message> Incoming = new Queue<Message>();
private static readonly object IncomingLock = new object();

public static Application.LogCallback LogCallback = delegate { };

static VisualStudioIntegration()
{
if (!VisualStudioEditor.IsEnabled)
return;

RunOnceOnUpdate(() =>
{
_messager = Messager.BindTo(MessagingPort());
_messager.ReceiveMessage += ReceiveMessage;
// Despite using ReuseAddress|!ExclusiveAddressUse, we can fail here:
// - if another application is using this port with exclusive access
// - or if the firewall is not properly configured
var messagingPort = MessagingPort();

try {
_messager = Messager.BindTo(messagingPort);
_messager.ReceiveMessage += ReceiveMessage;
}
catch (SocketException)
{
// We'll have a chance to try to rebind on next domain reload
Debug.LogWarning($"Unable to use UDP port {messagingPort} for VS/Unity messaging. You should check if another process is already bound to this port or if your firewall settings are compatible.");
}

RunOnShutdown(Shutdown);
});
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"name": "com.unity.ide.visualstudio",
"displayName": "Visual Studio Editor",
"description": "Code editor integration for supporting Visual Studio as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.",
"version": "2.0.1",
"version": "2.0.2",
"unity": "2020.1",
"unityRelease": "0a12",
"dependencies": {},
"relatedPackages": {
"com.unity.ide.visualstudio.tests": "2.0.1"
"com.unity.ide.visualstudio.tests": "2.0.2"
},
"upmCi": {
"footprint": "07f6b10869c0df5a69cfdcba85bf56c904b6d15d"
},
"repository": {
"footprint": "29b3412db92c0d78a94e0fdcaf3aa46387f7b415",
"type": "git",
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
"revision": "f8cace3617b9248d18f3a982b22fa3fb527e7b9b"
"type": "git",
"revision": "fe4c910c44c62de4bf224f458e3116184d414906"
}
}

0 comments on commit fc2dc75

Please sign in to comment.