com.unity.ide.visualstudio@2.0.22

## [2.0.22] - 2023-10-03

Integration:

- Add support for `XDG_DATA_DIRS` and `.desktop` files on Linux for `VS Code` discovery.
- Use compile-time platform-specifics instead of using runtime conditions.

Project generation:

- Suppress `USG0001` warnings.
- Mark referenced assemblies as private (to not copy extra files to output directory when building).
- Add Unity capability to SDK-Style projects.
- Prevent circular dependency errors with SDK-Style projects.
This commit is contained in:
Unity Technologies
2023-10-03 00:00:00 +00:00
parent 9fed958a9e
commit b28f5a3cbf
15 changed files with 203 additions and 80 deletions

View File

@@ -1,5 +1,20 @@
# Code Editor Package for Visual Studio # Code Editor Package for Visual Studio
## [2.0.22] - 2023-10-03
Integration:
- Add support for `XDG_DATA_DIRS` and `.desktop` files on Linux for `VS Code` discovery.
- Use compile-time platform-specifics instead of using runtime conditions.
Project generation:
- Suppress `USG0001` warnings.
- Mark referenced assemblies as private (to not copy extra files to output directory when building).
- Add Unity capability to SDK-Style projects.
- Prevent circular dependency errors with SDK-Style projects.
## [2.0.21] - 2023-09-05 ## [2.0.21] - 2023-09-05
Integration: Integration:
@@ -16,7 +31,6 @@ Project generation:
- Add `visualstudiotoolsforunity.vstuc` entry to `extensions.json` when needed. - Add `visualstudiotoolsforunity.vstuc` entry to `extensions.json` when needed.
- You can prevent the package from patching those configuration files by creating a `.vscode/.vstupatchdisable` file. - You can prevent the package from patching those configuration files by creating a `.vscode/.vstupatchdisable` file.
## [2.0.20] - 2023-06-27 ## [2.0.20] - 2023-06-27
Integration: Integration:
@@ -148,7 +162,7 @@ Documentation:
Integration: Integration:
- Remove com.unity.nuget.newtonsoft-json dependency in favor of the built-in JsonUtility for the VS Test Runner. - Remove `com.unity.nuget.newtonsoft-json` dependency in favor of the built-in JsonUtility for the VS Test Runner.
## [2.0.6] - 2021-01-20 ## [2.0.6] - 2021-01-20
@@ -186,7 +200,7 @@ Integration:
Project generation: Project generation:
- Added C#8 language support. - Added C#8 language support.
- Added UnityProjectGeneratorVersion property. - Added `UnityProjectGeneratorVersion` property.
- Local and Embedded packages are now selected by default for generation. - Local and Embedded packages are now selected by default for generation.
- Added support for asmdef root namespace. - Added support for asmdef root namespace.
@@ -208,7 +222,7 @@ Integration:
## [2.0.1] - 2020-03-19 ## [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). - 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).
- Use Unity's TypeCache to improve project generation speed. - Use Unity's `TypeCache` to improve project generation speed.
- Properly check for a managed assembly before displaying a warning regarding legacy PDB usage. - Properly check for a managed assembly before displaying a warning regarding legacy PDB usage.
- Add support for selective project generation (embedded, local, registry, git, builtin, player). - Add support for selective project generation (embedded, local, registry, git, builtin, player).
@@ -258,8 +272,8 @@ Integration:
## [1.0.4] - 2019-04-12 ## [1.0.4] - 2019-04-12
- Fixing null reference issue for callbacks to AssetPostProcessor. - Fixing null reference issue for callbacks to `AssetPostProcessor`.
- Ensure Path.GetFullPath does not get an empty string. - Ensure `Path.GetFullPath` does not get an empty string.
## [1.0.3] - 2019-01-01 ## [1.0.3] - 2019-01-01

View File

@@ -13,11 +13,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations() public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
{ {
#if UNITY_EDITOR_WIN
foreach (var installation in VisualStudioForWindowsInstallation.GetVisualStudioInstallations()) foreach (var installation in VisualStudioForWindowsInstallation.GetVisualStudioInstallations())
yield return installation; yield return installation;
#elif UNITY_EDITOR_OSX
foreach (var installation in VisualStudioForMacInstallation.GetVisualStudioInstallations()) foreach (var installation in VisualStudioForMacInstallation.GetVisualStudioInstallations())
yield return installation; yield return installation;
#endif
foreach (var installation in VisualStudioCodeInstallation.GetVisualStudioInstallations()) foreach (var installation in VisualStudioCodeInstallation.GetVisualStudioInstallations())
yield return installation; yield return installation;
@@ -27,12 +29,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
try try
{ {
#if UNITY_EDITOR_WIN
if (VisualStudioForWindowsInstallation.TryDiscoverInstallation(editorPath, out installation)) if (VisualStudioForWindowsInstallation.TryDiscoverInstallation(editorPath, out installation))
return true; return true;
#elif UNITY_EDITOR_OSX
if (VisualStudioForMacInstallation.TryDiscoverInstallation(editorPath, out installation)) if (VisualStudioForMacInstallation.TryDiscoverInstallation(editorPath, out installation))
return true; return true;
#endif
if (VisualStudioCodeInstallation.TryDiscoverInstallation(editorPath, out installation)) if (VisualStudioCodeInstallation.TryDiscoverInstallation(editorPath, out installation))
return true; return true;
} }
@@ -46,8 +49,11 @@ namespace Microsoft.Unity.VisualStudio.Editor
public static void Initialize() public static void Initialize()
{ {
#if UNITY_EDITOR_WIN
VisualStudioForWindowsInstallation.Initialize(); VisualStudioForWindowsInstallation.Initialize();
#elif UNITY_EDITOR_OSX
VisualStudioForMacInstallation.Initialize(); VisualStudioForMacInstallation.Initialize();
#endif
VisualStudioCodeInstallation.Initialize(); VisualStudioCodeInstallation.Initialize();
} }
} }

View File

@@ -27,9 +27,7 @@ namespace Microsoft.Unity.VisualStudio.Editor.Messaging
private void SetIOControl() private void SetIOControl()
{ {
if (!VisualStudioEditor.IsWindows) #if UNITY_EDITOR_WIN
return;
try try
{ {
const int SIO_UDP_CONNRESET = -1744830452; const int SIO_UDP_CONNRESET = -1744830452;
@@ -40,6 +38,7 @@ namespace Microsoft.Unity.VisualStudio.Editor.Messaging
{ {
// fallback // fallback
} }
#endif
} }
public static byte[] BufferFor(IAsyncResult result) public static byte[] BufferFor(IAsyncResult result)

View File

@@ -61,15 +61,18 @@ namespace Microsoft.Unity.VisualStudio.Editor
return CompilationPipeline.GetAssemblyNameFromScriptPath(path); return CompilationPipeline.GetAssemblyNameFromScriptPath(path);
} }
internal static readonly string AssemblyOutput = @"Temp\bin\Debug\".NormalizePathSeparators();
internal static readonly string PlayerAssemblyOutput = @"Temp\bin\Debug\Player\".NormalizePathSeparators();
public IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution) public IEnumerable<Assembly> GetAssemblies(Func<string, bool> shouldFileBePartOfSolution)
{ {
IEnumerable<Assembly> assemblies = GetAssembliesByType(AssembliesType.Editor, shouldFileBePartOfSolution, @"Temp\Bin\Debug\"); IEnumerable<Assembly> assemblies = GetAssembliesByType(AssembliesType.Editor, shouldFileBePartOfSolution, AssemblyOutput);
if (!ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies)) if (!ProjectGenerationFlag.HasFlag(ProjectGenerationFlag.PlayerAssemblies))
{ {
return assemblies; return assemblies;
} }
var playerAssemblies = GetAssembliesByType(AssembliesType.Player, shouldFileBePartOfSolution, @"Temp\Bin\Debug\Player\"); var playerAssemblies = GetAssembliesByType(AssembliesType.Player, shouldFileBePartOfSolution, PlayerAssemblyOutput);
return assemblies.Concat(playerAssemblies); return assemblies.Concat(playerAssemblies);
} }
@@ -98,7 +101,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
public string GetCompileOutputPath(string assemblyName) public string GetCompileOutputPath(string assemblyName)
{ {
return assemblyName.EndsWith(".Player", StringComparison.Ordinal) ? @"Temp\Bin\Debug\Player\" : @"Temp\Bin\Debug\"; // We need to keep this one for API surface check (AssemblyNameProvider is public), but not used anymore
throw new NotImplementedException();
} }
public IEnumerable<string> GetAllAssetPaths() public IEnumerable<string> GetAllAssetPaths()
@@ -207,7 +211,10 @@ namespace Microsoft.Unity.VisualStudio.Editor
public string GetAssemblyName(string assemblyOutputPath, string assemblyName) public string GetAssemblyName(string assemblyOutputPath, string assemblyName)
{ {
return assemblyOutputPath.EndsWith(@"\Player\", StringComparison.Ordinal) ? assemblyName + ".Player" : assemblyName; if (assemblyOutputPath == PlayerAssemblyOutput)
return assemblyName + ".Player";
return assemblyName;
} }
} }
} }

View File

@@ -12,6 +12,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
internal class LegacyStyleProjectGeneration : ProjectGeneration internal class LegacyStyleProjectGeneration : ProjectGeneration
{ {
internal override string StyleName => "Legacy";
public LegacyStyleProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNameProvider, IFileIO fileIoProvider, IGUIDGenerator guidGenerator) : base(tempDirectory, assemblyNameProvider, fileIoProvider, guidGenerator) public LegacyStyleProjectGeneration(string tempDirectory, IAssemblyNameProvider assemblyNameProvider, IFileIO fileIoProvider, IGUIDGenerator guidGenerator) : base(tempDirectory, assemblyNameProvider, fileIoProvider, guidGenerator)
{ {
} }
@@ -82,7 +84,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
internal override void GetProjectFooter(StringBuilder footerBuilder) internal override void GetProjectFooter(StringBuilder footerBuilder)
{ {
footerBuilder.Append(string.Join(k_WindowsNewline, footerBuilder.Append(string.Join(k_WindowsNewline,
@" <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />", $" <Import Project=\"{@"$(MSBuildToolsPath)\Microsoft.CSharp.targets".NormalizePathSeparators()}\" />",
@" <Target Name=""GenerateTargetFrameworkMonikerAttribute"" />", @" <Target Name=""GenerateTargetFrameworkMonikerAttribute"" />",
@" <!-- To modify your build process, add your task inside one of the targets below and uncomment it.", @" <!-- To modify your build process, add your task inside one of the targets below and uncomment it.",
@" Other similar extension points exist, see Microsoft.Common.targets.", @" Other similar extension points exist, see Microsoft.Common.targets.",

View File

@@ -87,6 +87,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
SetupProjectSupportedExtensions(); SetupProjectSupportedExtensions();
} }
internal virtual string StyleName => "";
/// <summary> /// <summary>
/// Syncs the scripting solution if any affected files are relevant. /// Syncs the scripting solution if any affected files are relevant.
/// </summary> /// </summary>
@@ -586,6 +588,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
var escapedFullPath = EscapedRelativePathFor(fullReference, out _); var escapedFullPath = EscapedRelativePathFor(fullReference, out _);
projectBuilder.Append(@" <Reference Include=""").Append(Path.GetFileNameWithoutExtension(escapedFullPath)).Append(@""">").Append(k_WindowsNewline); projectBuilder.Append(@" <Reference Include=""").Append(Path.GetFileNameWithoutExtension(escapedFullPath)).Append(@""">").Append(k_WindowsNewline);
projectBuilder.Append(" <HintPath>").Append(escapedFullPath).Append("</HintPath>").Append(k_WindowsNewline); projectBuilder.Append(" <HintPath>").Append(escapedFullPath).Append("</HintPath>").Append(k_WindowsNewline);
projectBuilder.Append(" <Private>False</Private>").Append(k_WindowsNewline);
projectBuilder.Append(" </Reference>").Append(k_WindowsNewline); projectBuilder.Append(" </Reference>").Append(k_WindowsNewline);
} }
@@ -594,7 +597,11 @@ namespace Microsoft.Unity.VisualStudio.Editor
return Path.Combine(ProjectDirectory, $"{m_AssemblyNameProvider.GetAssemblyName(assembly.outputPath, assembly.name)}.csproj"); return Path.Combine(ProjectDirectory, $"{m_AssemblyNameProvider.GetAssemblyName(assembly.outputPath, assembly.name)}.csproj");
} }
private static readonly Regex InvalidCharactersRegexPattern = new Regex(@"\?|&|\*|""|<|>|\||#|%|\^|;" + (VisualStudioEditor.IsWindows ? "" : "|:")); #if UNITY_EDITOR_WIN
private static readonly Regex InvalidCharactersRegexPattern = new Regex(@"\?|&|\*|""|<|>|\||#|%|\^|;", RegexOptions.Compiled);
#else
private static readonly Regex InvalidCharactersRegexPattern = new Regex(@"\?|&|\*|""|<|>|\||#|%|\^|;|:", RegexOptions.Compiled);
#endif
public string SolutionFile() public string SolutionFile()
{ {
@@ -763,6 +770,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
internal static void GetProjectHeaderConfigurations(ProjectProperties properties, StringBuilder headerBuilder) internal static void GetProjectHeaderConfigurations(ProjectProperties properties, StringBuilder headerBuilder)
{ {
const string NoWarn = "0169;USG0001";
headerBuilder.Append(@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">").Append(k_WindowsNewline); headerBuilder.Append(@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">").Append(k_WindowsNewline);
headerBuilder.Append(@" <DebugSymbols>true</DebugSymbols>").Append(k_WindowsNewline); headerBuilder.Append(@" <DebugSymbols>true</DebugSymbols>").Append(k_WindowsNewline);
headerBuilder.Append(@" <DebugType>full</DebugType>").Append(k_WindowsNewline); headerBuilder.Append(@" <DebugType>full</DebugType>").Append(k_WindowsNewline);
@@ -771,16 +780,16 @@ namespace Microsoft.Unity.VisualStudio.Editor
headerBuilder.Append(@" <DefineConstants>").Append(string.Join(";", properties.Defines)).Append(@"</DefineConstants>").Append(k_WindowsNewline); headerBuilder.Append(@" <DefineConstants>").Append(string.Join(";", properties.Defines)).Append(@"</DefineConstants>").Append(k_WindowsNewline);
headerBuilder.Append(@" <ErrorReport>prompt</ErrorReport>").Append(k_WindowsNewline); headerBuilder.Append(@" <ErrorReport>prompt</ErrorReport>").Append(k_WindowsNewline);
headerBuilder.Append(@" <WarningLevel>4</WarningLevel>").Append(k_WindowsNewline); headerBuilder.Append(@" <WarningLevel>4</WarningLevel>").Append(k_WindowsNewline);
headerBuilder.Append(@" <NoWarn>0169</NoWarn>").Append(k_WindowsNewline); headerBuilder.Append(@" <NoWarn>").Append(NoWarn).Append("</NoWarn>").Append(k_WindowsNewline);
headerBuilder.Append(@" <AllowUnsafeBlocks>").Append(properties.Unsafe).Append(@"</AllowUnsafeBlocks>").Append(k_WindowsNewline); headerBuilder.Append(@" <AllowUnsafeBlocks>").Append(properties.Unsafe).Append(@"</AllowUnsafeBlocks>").Append(k_WindowsNewline);
headerBuilder.Append(@" </PropertyGroup>").Append(k_WindowsNewline); headerBuilder.Append(@" </PropertyGroup>").Append(k_WindowsNewline);
headerBuilder.Append(@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">").Append(k_WindowsNewline); headerBuilder.Append(@" <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">").Append(k_WindowsNewline);
headerBuilder.Append(@" <DebugType>pdbonly</DebugType>").Append(k_WindowsNewline); headerBuilder.Append(@" <DebugType>pdbonly</DebugType>").Append(k_WindowsNewline);
headerBuilder.Append(@" <Optimize>true</Optimize>").Append(k_WindowsNewline); headerBuilder.Append(@" <Optimize>true</Optimize>").Append(k_WindowsNewline);
headerBuilder.Append(@" <OutputPath>Temp\bin\Release\</OutputPath>").Append(k_WindowsNewline); headerBuilder.Append($" <OutputPath>{@"Temp\bin\Release\".NormalizePathSeparators()}</OutputPath>").Append(k_WindowsNewline);
headerBuilder.Append(@" <ErrorReport>prompt</ErrorReport>").Append(k_WindowsNewline); headerBuilder.Append(@" <ErrorReport>prompt</ErrorReport>").Append(k_WindowsNewline);
headerBuilder.Append(@" <WarningLevel>4</WarningLevel>").Append(k_WindowsNewline); headerBuilder.Append(@" <WarningLevel>4</WarningLevel>").Append(k_WindowsNewline);
headerBuilder.Append(@" <NoWarn>0169</NoWarn>").Append(k_WindowsNewline); headerBuilder.Append(@" <NoWarn>").Append(NoWarn).Append("</NoWarn>").Append(k_WindowsNewline);
headerBuilder.Append(@" <AllowUnsafeBlocks>").Append(properties.Unsafe).Append(@"</AllowUnsafeBlocks>").Append(k_WindowsNewline); headerBuilder.Append(@" <AllowUnsafeBlocks>").Append(properties.Unsafe).Append(@"</AllowUnsafeBlocks>").Append(k_WindowsNewline);
headerBuilder.Append(@" </PropertyGroup>").Append(k_WindowsNewline); headerBuilder.Append(@" </PropertyGroup>").Append(k_WindowsNewline);
} }
@@ -822,7 +831,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
} }
} }
internal static void GetProjectHeaderVstuFlavoring(ProjectProperties properties, StringBuilder headerBuilder, bool includeProjectTypeGuids = true) internal void GetProjectHeaderVstuFlavoring(ProjectProperties properties, StringBuilder headerBuilder, bool includeProjectTypeGuids = true)
{ {
// Flavoring // Flavoring
headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline); headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline);
@@ -834,6 +843,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
headerBuilder.Append(@" <UnityProjectGenerator>Package</UnityProjectGenerator>").Append(k_WindowsNewline); headerBuilder.Append(@" <UnityProjectGenerator>Package</UnityProjectGenerator>").Append(k_WindowsNewline);
headerBuilder.Append(@" <UnityProjectGeneratorVersion>").Append(properties.FlavoringPackageVersion).Append(@"</UnityProjectGeneratorVersion>").Append(k_WindowsNewline); headerBuilder.Append(@" <UnityProjectGeneratorVersion>").Append(properties.FlavoringPackageVersion).Append(@"</UnityProjectGeneratorVersion>").Append(k_WindowsNewline);
headerBuilder.Append(@" <UnityProjectGeneratorStyle>").Append(StyleName).Append("</UnityProjectGeneratorStyle>").Append(k_WindowsNewline);
headerBuilder.Append(@" <UnityProjectType>").Append(properties.FlavoringProjectType).Append(@"</UnityProjectType>").Append(k_WindowsNewline); headerBuilder.Append(@" <UnityProjectType>").Append(properties.FlavoringProjectType).Append(@"</UnityProjectType>").Append(k_WindowsNewline);
headerBuilder.Append(@" <UnityBuildTarget>").Append(properties.FlavoringBuildTarget).Append(@"</UnityBuildTarget>").Append(k_WindowsNewline); headerBuilder.Append(@" <UnityBuildTarget>").Append(properties.FlavoringBuildTarget).Append(@"</UnityBuildTarget>").Append(k_WindowsNewline);
headerBuilder.Append(@" <UnityVersion>").Append(properties.FlavoringUnityVersion).Append(@"</UnityVersion>").Append(k_WindowsNewline); headerBuilder.Append(@" <UnityVersion>").Append(properties.FlavoringUnityVersion).Append(@"</UnityVersion>").Append(k_WindowsNewline);

View File

@@ -4,6 +4,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using UnityEditor.Compilation; using UnityEditor.Compilation;
@@ -13,6 +14,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
internal class SdkStyleProjectGeneration : ProjectGeneration internal class SdkStyleProjectGeneration : ProjectGeneration
{ {
internal override string StyleName => "SDK";
internal class SdkStyleAssemblyNameProvider : AssemblyNameProvider internal class SdkStyleAssemblyNameProvider : AssemblyNameProvider
{ {
// disable PlayerGeneration with SdkStyle projects // disable PlayerGeneration with SdkStyle projects
@@ -27,12 +30,42 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
} }
internal static readonly string[] SupportedCapabilities = new string[]
{
"Unity",
};
internal static readonly string[] UnsupportedCapabilities = new string[]
{
"LaunchProfiles",
"SharedProjectReferences",
"ReferenceManagerSharedProjects",
"ProjectReferences",
"ReferenceManagerProjects",
"COMReferences",
"ReferenceManagerCOM",
"AssemblyReferences",
"ReferenceManagerAssemblies",
};
internal override void GetProjectHeader(ProjectProperties properties, out StringBuilder headerBuilder) internal override void GetProjectHeader(ProjectProperties properties, out StringBuilder headerBuilder)
{ {
headerBuilder = new StringBuilder(); headerBuilder = new StringBuilder();
headerBuilder.Append(@"<Project ToolsVersion=""Current"" Sdk=""Microsoft.NET.Sdk"">").Append(k_WindowsNewline); headerBuilder.Append(@"<Project ToolsVersion=""Current"">").Append(k_WindowsNewline);
headerBuilder.Append(@" <!-- Generated file, do not modify, your changes will be overwritten (use AssetPostprocessor.OnGeneratedCSProject) -->").Append(k_WindowsNewline); headerBuilder.Append(@" <!-- Generated file, do not modify, your changes will be overwritten (use AssetPostprocessor.OnGeneratedCSProject) -->").Append(k_WindowsNewline);
// Prevent circular dependency issues see https://github.com/microsoft/vscode-dotnettools/issues/401
// We need a dedicated subfolder for each project in obj, else depending on the build order, nuget cache files could be overwritten
// We need to do this before common.props, else we'll have a MSB3539 The value of the property "BaseIntermediateOutputPath" was modified after it was used by MSBuild
headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline);
headerBuilder.Append($" <BaseIntermediateOutputPath>{@"Temp\obj\$(Configuration)\$(MSBuildProjectName)".NormalizePathSeparators()}</BaseIntermediateOutputPath>").Append(k_WindowsNewline);
headerBuilder.Append(@" <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>").Append(k_WindowsNewline);
headerBuilder.Append(@" </PropertyGroup>").Append(k_WindowsNewline);
// Supported capabilities
GetCapabilityBlock(headerBuilder, "Sdk.props", "Include", SupportedCapabilities);
headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline); headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline);
headerBuilder.Append(@" <GenerateAssemblyInfo>false</GenerateAssemblyInfo>").Append(k_WindowsNewline); headerBuilder.Append(@" <GenerateAssemblyInfo>false</GenerateAssemblyInfo>").Append(k_WindowsNewline);
headerBuilder.Append(@" <EnableDefaultItems>false</EnableDefaultItems>").Append(k_WindowsNewline); headerBuilder.Append(@" <EnableDefaultItems>false</EnableDefaultItems>").Append(k_WindowsNewline);
@@ -76,7 +109,21 @@ namespace Microsoft.Unity.VisualStudio.Editor
internal override void GetProjectFooter(StringBuilder footerBuilder) internal override void GetProjectFooter(StringBuilder footerBuilder)
{ {
// Unsupported capabilities
GetCapabilityBlock(footerBuilder, "Sdk.targets", "Remove", UnsupportedCapabilities);
footerBuilder.Append("</Project>").Append(k_WindowsNewline); footerBuilder.Append("</Project>").Append(k_WindowsNewline);
} }
internal static void GetCapabilityBlock(StringBuilder footerBuilder, string import, string attribute, string[] capabilities)
{
footerBuilder.Append($@" <Import Project=""{import}"" Sdk=""Microsoft.NET.Sdk"" />").Append(k_WindowsNewline);
footerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
foreach (var capability in capabilities)
{
footerBuilder.Append($@" <ProjectCapability {attribute}=""{capability}"" />").Append(k_WindowsNewline);
}
footerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}
} }
} }

View File

@@ -66,13 +66,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static bool IsCandidateForDiscovery(string path) private static bool IsCandidateForDiscovery(string path)
{ {
if (VisualStudioEditor.IsOSX) #if UNITY_EDITOR_OSX
return Directory.Exists(path) && Regex.IsMatch(path, ".*Code.*.app$", RegexOptions.IgnoreCase); return Directory.Exists(path) && Regex.IsMatch(path, ".*Code.*.app$", RegexOptions.IgnoreCase);
#elif UNITY_EDITOR_WIN
if (VisualStudioEditor.IsWindows) return File.Exists(path) && Regex.IsMatch(path, ".*Code.*.exe$", RegexOptions.IgnoreCase);
return File.Exists(path) && Regex.IsMatch(path, ".*Code.*.exe$", RegexOptions.IgnoreCase); #else
return File.Exists(path) && path.EndsWith("code", StringComparison.OrdinalIgnoreCase); return File.Exists(path) && path.EndsWith("code", StringComparison.OrdinalIgnoreCase);
#endif
} }
[Serializable] [Serializable]
@@ -99,17 +99,23 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
var manifestBase = GetRealPath(editorPath); var manifestBase = GetRealPath(editorPath);
if (VisualStudioEditor.IsWindows) // on Windows, editorPath is a file, resources as subdirectory #if UNITY_EDITOR_WIN
manifestBase = IOPath.GetDirectoryName(manifestBase); // on Windows, editorPath is a file, resources as subdirectory
else if (VisualStudioEditor.IsOSX) // on Mac, editorPath is a directory manifestBase = IOPath.GetDirectoryName(manifestBase);
manifestBase = IOPath.Combine(manifestBase, "Contents"); #elif UNITY_EDITOR_OSX
else // on Linux, editorPath is a file, in a bin sub-directory // on Mac, editorPath is a directory
manifestBase = Directory.GetParent(manifestBase)?.Parent?.FullName; manifestBase = IOPath.Combine(manifestBase, "Contents");
#else
// on Linux, editorPath is a file, in a bin sub-directory
var parent = Directory.GetParent(manifestBase);
// but we can link to [vscode]/code or [vscode]/bin/code
manifestBase = parent?.Name == "bin" ? parent.Parent?.FullName : parent?.FullName;
#endif
if (manifestBase == null) if (manifestBase == null)
return false; return false;
var manifestFullPath = IOPath.Combine(manifestBase, @"resources", "app", "package.json"); var manifestFullPath = IOPath.Combine(manifestBase, "resources", "app", "package.json");
if (File.Exists(manifestFullPath)) if (File.Exists(manifestFullPath))
{ {
var manifest = JsonUtility.FromJson<VisualStudioCodeManifest>(File.ReadAllText(manifestFullPath)); var manifest = JsonUtility.FromJson<VisualStudioCodeManifest>(File.ReadAllText(manifestFullPath));
@@ -138,30 +144,29 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
var candidates = new List<string>(); var candidates = new List<string>();
if (VisualStudioEditor.IsWindows) #if UNITY_EDITOR_WIN
{ var localAppPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs");
var localAppPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs"); var programFiles = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
var programFiles = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
foreach (var basePath in new[] {localAppPath, programFiles}) foreach (var basePath in new[] {localAppPath, programFiles})
{
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code", "Code.exe"));
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code Insiders", "Code - Insiders.exe"));
}
}
else if (VisualStudioEditor.IsOSX)
{ {
var appPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)); candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code", "Code.exe"));
candidates.AddRange(Directory.EnumerateDirectories(appPath, "Visual Studio Code*.app")); candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code Insiders", "Code - Insiders.exe"));
}
else
{
candidates.Add("/usr/bin/code");
candidates.Add("/bin/code");
candidates.Add("/usr/local/bin/code");
} }
#elif UNITY_EDITOR_OSX
var appPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
candidates.AddRange(Directory.EnumerateDirectories(appPath, "Visual Studio Code*.app"));
#elif UNITY_EDITOR_LINUX
// Well known locations
candidates.Add("/usr/bin/code");
candidates.Add("/bin/code");
candidates.Add("/usr/local/bin/code");
foreach (var candidate in candidates) // Preference ordered base directories relative to which desktop files should be searched
candidates.AddRange(GetXdgCandidates());
#endif
foreach (var candidate in candidates.Distinct())
{ {
if (TryDiscoverInstallation(candidate, out var installation)) if (TryDiscoverInstallation(candidate, out var installation))
yield return installation; yield return installation;
@@ -169,6 +174,41 @@ namespace Microsoft.Unity.VisualStudio.Editor
} }
#if UNITY_EDITOR_LINUX #if UNITY_EDITOR_LINUX
private static readonly Regex DesktopFileExecEntry = new Regex(@"Exec=(\S+)", RegexOptions.Singleline | RegexOptions.Compiled);
private static IEnumerable<string> GetXdgCandidates()
{
var envdirs = Environment.GetEnvironmentVariable("XDG_DATA_DIRS");
if (string.IsNullOrEmpty(envdirs))
yield break;
var dirs = envdirs.Split(':');
foreach(var dir in dirs)
{
Match match = null;
try
{
var desktopFile = IOPath.Combine(dir, "applications/code.desktop");
if (!File.Exists(desktopFile))
continue;
var content = File.ReadAllText(desktopFile);
match = DesktopFileExecEntry.Match(content);
}
catch
{
// do not fail if we cannot read desktop file
}
if (match == null || !match.Success)
continue;
yield return match.Groups[1].Value;
break;
}
}
[System.Runtime.InteropServices.DllImport ("libc")] [System.Runtime.InteropServices.DllImport ("libc")]
private static extern int readlink(string path, byte[] buffer, int buflen); private static extern int readlink(string path, byte[] buffer, int buflen);
@@ -475,13 +515,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static ProcessStartInfo ProcessStartInfoFor(string application, string arguments) private static ProcessStartInfo ProcessStartInfoFor(string application, string arguments)
{ {
if (!VisualStudioEditor.IsOSX) #if UNITY_EDITOR_OSX
return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect: false);
// wrap with built-in OSX open feature // wrap with built-in OSX open feature
arguments = $"-n \"{application}\" --args {arguments}"; arguments = $"-n \"{application}\" --args {arguments}";
application = "open"; application = "open";
return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect:false, shell: true); return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect:false, shell: true);
#else
return ProcessRunner.ProcessStartInfoFor(application, arguments, redirect: false);
#endif
} }
public static void Initialize() public static void Initialize()

View File

@@ -21,9 +21,6 @@ namespace Microsoft.Unity.VisualStudio.Editor
[InitializeOnLoad] [InitializeOnLoad]
public class VisualStudioEditor : IExternalCodeEditor public class VisualStudioEditor : IExternalCodeEditor
{ {
internal static bool IsOSX => Application.platform == RuntimePlatform.OSXEditor;
internal static bool IsWindows => !IsOSX && Path.DirectorySeparatorChar == FileUtility.WinSeparator && Environment.NewLine == "\r\n";
CodeEditor.Installation[] IExternalCodeEditor.Installations => _discoverInstallations CodeEditor.Installation[] IExternalCodeEditor.Installations => _discoverInstallations
.Result .Result
.Values .Values

View File

@@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
#if UNITY_EDITOR_OSX
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@@ -101,7 +103,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static bool IsCandidateForDiscovery(string path) private static bool IsCandidateForDiscovery(string path)
{ {
return Directory.Exists(path) && VisualStudioEditor.IsOSX && Regex.IsMatch(path, "Visual\\s?Studio(?!.*Code.*).*.app$", RegexOptions.IgnoreCase); return Directory.Exists(path) && Regex.IsMatch(path, "Visual\\s?Studio(?!.*Code.*).*.app$", RegexOptions.IgnoreCase);
} }
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation) public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation)
@@ -144,9 +146,6 @@ namespace Microsoft.Unity.VisualStudio.Editor
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations() public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
{ {
if (!VisualStudioEditor.IsOSX)
yield break;
var candidates = Directory.EnumerateDirectories("/Applications", "*.app"); var candidates = Directory.EnumerateDirectories("/Applications", "*.app");
foreach (var candidate in candidates) foreach (var candidate in candidates)
{ {
@@ -178,3 +177,5 @@ namespace Microsoft.Unity.VisualStudio.Editor
} }
} }
} }
#endif

View File

@@ -3,6 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
#if UNITY_EDITOR_WIN
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
@@ -126,7 +128,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static bool IsCandidateForDiscovery(string path) private static bool IsCandidateForDiscovery(string path)
{ {
return File.Exists(path) && VisualStudioEditor.IsWindows && Regex.IsMatch(path, "devenv.exe$", RegexOptions.IgnoreCase); return File.Exists(path) && Regex.IsMatch(path, "devenv.exe$", RegexOptions.IgnoreCase);
} }
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation) public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation)
@@ -169,9 +171,6 @@ namespace Microsoft.Unity.VisualStudio.Editor
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations() public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
{ {
if (!VisualStudioEditor.IsWindows)
yield break;
foreach (var installation in QueryVsWhere()) foreach (var installation in QueryVsWhere())
yield return installation; yield return installation;
} }
@@ -373,8 +372,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
public static void Initialize() public static void Initialize()
{ {
if (VisualStudioEditor.IsWindows) _vsWherePath = FileUtility.GetPackageAssetFullPath("Editor", "VSWhere", "vswhere.exe");
_vsWherePath = FileUtility.GetPackageAssetFullPath("Editor", "VSWhere", "vswhere.exe");
} }
} }
} }
#endif

View File

@@ -106,10 +106,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
private static void RunOnShutdown(Action action) private static void RunOnShutdown(Action action)
{ {
// Mono on OSX has all kinds of quirks on AppDomain shutdown // Mono on OSX has all kinds of quirks on AppDomain shutdown
if (!VisualStudioEditor.IsWindows) #if UNITY_EDITOR_WIN
return;
AppDomain.CurrentDomain.DomainUnload += (_, __) => action(); AppDomain.CurrentDomain.DomainUnload += (_, __) => action();
#endif
} }
private static int DebuggingPort() private static int DebuggingPort()

View File

@@ -2,25 +2,25 @@
"name": "com.unity.ide.visualstudio", "name": "com.unity.ide.visualstudio",
"displayName": "Visual Studio Editor", "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.", "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.21", "version": "2.0.22",
"unity": "2019.4", "unity": "2019.4",
"unityRelease": "25f1", "unityRelease": "25f1",
"dependencies": { "dependencies": {
"com.unity.test-framework": "1.1.9" "com.unity.test-framework": "1.1.9"
}, },
"relatedPackages": { "relatedPackages": {
"com.unity.ide.visualstudio.tests": "2.0.21" "com.unity.ide.visualstudio.tests": "2.0.22"
}, },
"_upm": { "_upm": {
"changelog": "Integration:\n\n- Only disable the legacy `com.unity.ide.vscode` package going forward.\n- Fix json parsing issues with specific non-UTF code pages.\n\nProject generation:\n\n- Target `netstandard2.1` instead of `netstandard2.0`.\n- Set `defaultSolution` in `settings.json`.\n- Remove `files.exclude` entries for root `csproj` and `sln` files in `settings.json` when needed.\n- Add `vstuc` launch configuration to `launch.json` when needed.\n- Add `visualstudiotoolsforunity.vstuc` entry to `extensions.json` when needed.\n- You can prevent the package from patching those configuration files by creating a `.vscode/.vstupatchdisable` file." "changelog": "Integration:\n\n- Add support for `XDG_DATA_DIRS` and `.desktop` files on Linux for `VS Code` discovery.\n- Use compile-time platform-specifics instead of using runtime conditions.\n\nProject generation:\n\n- Suppress `USG0001` warnings.\n- Mark referenced assemblies as private (to not copy extra files to output directory when building).\n- Add Unity capability to SDK-Style projects.\n- Prevent circular dependency errors with SDK-Style projects."
}, },
"upmCi": { "upmCi": {
"footprint": "33ecd838a074080a82176ca86b21c837ba396a28" "footprint": "0b7347d4363afca9be389b61f0e25489ae3995b8"
}, },
"documentationUrl": "https://docs.unity3d.com/Packages/com.unity.ide.visualstudio@2.0/manual/index.html", "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.ide.visualstudio@2.0/manual/index.html",
"repository": { "repository": {
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git", "url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
"type": "git", "type": "git",
"revision": "eb2b500b99f6429d3d9dcb8acbcbd366dfbb42be" "revision": "700b44077345e97d37d464ff25507638983aed64"
} }
} }