Skip to content

Commit 68bdf49

Browse files
committed
Add Unity capability to SDK generation
1 parent 21e1b3f commit 68bdf49

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/SdkStyleProjectGeneration.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
66

7+
using System;
78
using System.IO;
89
using System.Text;
910
using UnityEditor.Compilation;
@@ -29,12 +30,36 @@ public SdkStyleProjectGeneration() : base(
2930
{
3031
}
3132

33+
internal enum SupportedCapability
34+
{
35+
Unity
36+
}
37+
internal static readonly string[] SupportedCapabilities = Enum.GetNames(typeof(SupportedCapability));
38+
39+
internal enum UnsupportedCapability
40+
{
41+
LaunchProfiles,
42+
SharedProjectReferences,
43+
ReferenceManagerSharedProjects,
44+
ProjectReferences,
45+
ReferenceManagerProjects,
46+
COMReferences,
47+
ReferenceManagerCOM,
48+
AssemblyReferences,
49+
ReferenceManagerAssemblies
50+
}
51+
internal static readonly string[] UnsupportedCapabilities = Enum.GetNames(typeof(UnsupportedCapability));
52+
3253
internal override void GetProjectHeader(ProjectProperties properties, out StringBuilder headerBuilder)
3354
{
3455
headerBuilder = new StringBuilder();
3556

36-
headerBuilder.Append(@"<Project ToolsVersion=""Current"" Sdk=""Microsoft.NET.Sdk"">").Append(k_WindowsNewline);
57+
headerBuilder.Append(@"<Project ToolsVersion=""Current"">").Append(k_WindowsNewline);
3758
headerBuilder.Append(@" <!-- Generated file, do not modify, your changes will be overwritten (use AssetPostprocessor.OnGeneratedCSProject) -->").Append(k_WindowsNewline);
59+
60+
// Supported capabilities
61+
GetCapabilityBlock(headerBuilder, "Sdk.props", "Include", SupportedCapabilities);
62+
3863
headerBuilder.Append(@" <PropertyGroup>").Append(k_WindowsNewline);
3964
headerBuilder.Append(@" <GenerateAssemblyInfo>false</GenerateAssemblyInfo>").Append(k_WindowsNewline);
4065
headerBuilder.Append(@" <EnableDefaultItems>false</EnableDefaultItems>").Append(k_WindowsNewline);
@@ -78,7 +103,23 @@ internal override void AppendProjectReference(Assembly assembly, Assembly refere
78103

79104
internal override void GetProjectFooter(StringBuilder footerBuilder)
80105
{
106+
// Unsupported capabilities
107+
GetCapabilityBlock(footerBuilder, "Sdk.targets", "Remove", UnsupportedCapabilities);
108+
81109
footerBuilder.Append("</Project>").Append(k_WindowsNewline);
82110
}
111+
112+
internal static void GetCapabilityBlock(StringBuilder footerBuilder, string import, string attribute, string[] capabilities)
113+
{
114+
// Unsupported capabilities
115+
footerBuilder.Append($@" <Import Project=""{import}"" Sdk=""Microsoft.NET.Sdk"" />").Append(k_WindowsNewline);
116+
footerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
117+
foreach (var capability in capabilities)
118+
{
119+
footerBuilder.Append($@" <ProjectCapability {attribute}=""{capability}"" />").Append(k_WindowsNewline);
120+
}
121+
footerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
122+
}
123+
83124
}
84125
}

0 commit comments

Comments
 (0)