Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 3918ced

Browse files
committed
Allow winmdobj output type as CsWinRT component
1 parent 3799b68 commit 3918ced

File tree

6 files changed

+34
-0
lines changed

6 files changed

+34
-0
lines changed

src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ private bool IsSupportedOutputType(ProjectOutputType type) =>
237237
ProjectOutputType.Library => true,
238238
ProjectOutputType.WinExe => true,
239239
ProjectOutputType.AppContainerExe => true,
240+
ProjectOutputType.WinMdObj => true,
240241
_ => false
241242
};
242243

@@ -283,6 +284,10 @@ private ProjectOutputType GetProjectOutputType(IProjectRootElement root, Project
283284
{
284285
return ProjectOutputType.AppContainerExe;
285286
}
287+
else if (ProjectPropertyHelpers.IsWinMdObjProjectType(outputTypeNode))
288+
{
289+
return ProjectOutputType.WinMdObj;
290+
}
286291
else
287292
{
288293
return ProjectOutputType.Other;

src/MSBuild.Abstractions/ProjectOutputType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum ProjectOutputType
1313
Exe,
1414
WinExe,
1515
AppContainerExe,
16+
WinMdObj,
1617
Other,
1718
None
1819
}

src/MSBuild.Abstractions/ProjectPropertyHelpers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ public static bool IsWinExeOutputType(ProjectPropertyElement prop) =>
170170
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
171171
&& prop.Value.Equals(MSBuildFacts.WinExeOutputType, StringComparison.OrdinalIgnoreCase);
172172

173+
/// <summary>
174+
/// Checks if an OutputType node is Exe.
175+
/// </summary>
176+
public static bool IsWinMdObjProjectType(ProjectPropertyElement prop) =>
177+
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
178+
&& prop.Value.Equals(MSBuildFacts.WinMdObjOutputType, StringComparison.OrdinalIgnoreCase);
179+
173180
public static bool IsVisualBasicProject(ProjectPropertyElement prop) =>
174181
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').Any(guidString => Guid.Parse(guidString) == MSBuildFacts.LanguageProjectTypeVisualBasic);
175182

src/MSBuild.Conversion.Facts/MSBuildFacts.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public static class MSBuildFacts
259259
Guid.Parse("{F2A71F9B-5D33-465A-A702-920D77279786}") // F#
260260
);
261261

262+
public static readonly (string Name, string Version) CsWinRTPackageReference = (Name: "Microsoft.Windows.CsWinRT", Version: "1.6.4");
263+
262264
public const string DefaultSDKAttribute = "Microsoft.NET.Sdk";
263265
public const string LowestFrameworkVersionWithSystemValueTuple = "net47";
264266
public const string SharedProjectsImportLabel = "Shared";
@@ -290,6 +292,7 @@ public static class MSBuildFacts
290292
public const string ExeOutputType = "Exe";
291293
public const string WinExeOutputType = "WinExe";
292294
public const string AppContainerExeOutputType = "AppContainerExe";
295+
public const string WinMdObjOutputType = "winmdobj";
293296
public const string NuGetPackageImportStampNodeName = "NuGetPackageImportStamp";
294297
public const string ReferencePathNodeName = "ReferencePath";
295298
public const string LegacyTargetFrameworkPropertyNodeName = "TargetFrameworkIdentifier";
@@ -313,5 +316,6 @@ public static class MSBuildFacts
313316
public const string TargetPlatformIdentifierNodeName = "TargetPlatformIdentifier";
314317
public const string UapValue = "UAP";
315318
public const string TargetPlatformVersionNodeName = "TargetPlatformVersion";
319+
public const string CsWinRTComponentName = "CsWinRTComponent";
316320
}
317321
}

src/MSBuild.Conversion.Project/Converter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void Convert(string outputPath)
4242

4343
// Now we can convert the project over
4444
.ChangeImportsAndAddSdkAttribute(_sdkBaselineProject, _forceRemoveCustomImports)
45+
.AddCsWinRTReferenceAndComponentProperty(_sdkBaselineProject)
4546
.UpdateOutputTypeProperty(_sdkBaselineProject)
4647
.RemoveDefaultedProperties(_sdkBaselineProject, _differs)
4748
.RemoveUnnecessaryPropertiesNotInSDKByDefault(_sdkBaselineProject.ProjectStyle)

src/MSBuild.Conversion.Project/ProjectRootElementExtensionsForConversion.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ public static IProjectRootElement ChangeImportsAndAddSdkAttribute(this IProjectR
6565
return projectRootElement;
6666
}
6767

68+
public static IProjectRootElement AddCsWinRTReferenceAndComponentProperty(this IProjectRootElement projectRootElement, BaselineProject baselineProject)
69+
{
70+
if (baselineProject.OutputType == ProjectOutputType.WinMdObj)
71+
{
72+
var topLevelPropGroup = MSBuildHelpers.GetOrCreateTopLevelPropertyGroup(baselineProject, projectRootElement);
73+
topLevelPropGroup.AddProperty(MSBuildFacts.CsWinRTComponentName, "true");
74+
75+
var itemGroup = projectRootElement.ItemGroups.Where(ig => ig.Items.Where(i => i.ItemType == MSBuildFacts.MSBuildPackageReferenceName).Any())
76+
.FirstOrDefault() ?? projectRootElement.AddItemGroup();
77+
AddPackageReferenceElement(itemGroup, MSBuildFacts.CsWinRTPackageReference.Name, MSBuildFacts.CsWinRTPackageReference.Version);
78+
}
79+
80+
return projectRootElement;
81+
}
82+
6883
public static IProjectRootElement UpdateOutputTypeProperty(this IProjectRootElement projectRootElement, BaselineProject baselineProject)
6984
{
7085
var outputTypeNode = projectRootElement.GetOutputTypeNode();
@@ -76,6 +91,7 @@ public static IProjectRootElement UpdateOutputTypeProperty(this IProjectRootElem
7691
ProjectOutputType.Library => MSBuildFacts.LibraryOutputType,
7792
ProjectOutputType.WinExe => MSBuildFacts.WinExeOutputType,
7893
ProjectOutputType.AppContainerExe => MSBuildFacts.WinExeOutputType,
94+
ProjectOutputType.WinMdObj => MSBuildFacts.LibraryOutputType,
7995
_ => throw new InvalidOperationException("Unsupported output type: " + baselineProject.OutputType)
8096
};
8197
}

0 commit comments

Comments
 (0)