-
Notifications
You must be signed in to change notification settings - Fork 178
Support winrt consumption using CsWinRT reference #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
defd37a
09d08f0
9734f8c
a653d2a
87d11a3
743b674
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
@@ -18,6 +20,10 @@ public class WinUIPropertiesUpdater : IUpdater<IProject> | |
| { | ||
| public const string RuleID = "UA302"; | ||
|
|
||
| private const string CsWinRTLogMessage = "A CsWinRTIncludes property with value {0} has been added.\n" + | ||
|
ujjwalchadha marked this conversation as resolved.
Outdated
|
||
| "If your project assembly name differs from {0}, update this value with the assembly name.\n" + | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this message printed for the component scenario where the project assembly name comes into play or is it printed for the vcxproj references scenario?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is printed for all the vcxproj scenarios (There seems to be no good way to parse the assembly name as we are unable to load cpp projects). So, whenever we add a CsWinRTIncludes property with the name same as the vcxproj file name, we show this message on the console. |
||
| "Read more about CsWinRT here: https://docs.microsoft.com/en-us/windows/apps/develop/platform/csharp-winrt/"; | ||
|
ujjwalchadha marked this conversation as resolved.
Outdated
|
||
|
|
||
| public string Id => typeof(WinUIPropertiesUpdater).FullName; | ||
|
|
||
| public string Title => "Update WinUI Project Properties"; | ||
|
|
@@ -69,6 +75,19 @@ public async Task<IUpdaterResult> ApplyAsync(IUpgradeContext context, ImmutableA | |
| } | ||
| } | ||
|
|
||
| foreach (var projRef in project.AllProjectReferences) | ||
| { | ||
| if (projRef.Contains(".vcxproj")) | ||
| { | ||
| var projectName = ParseProjectNameWithExtension(projRef, ".vcxproj"); | ||
| var csWinRTIncludesValue = projectFile.GetPropertyValue("CsWinRTIncludes") ?? string.Empty; | ||
|
ujjwalchadha marked this conversation as resolved.
Outdated
|
||
| var delimiter = csWinRTIncludesValue.Trim().Length == 0 || csWinRTIncludesValue.EndsWith(";") ? string.Empty : ";"; | ||
| projectFile.SetPropertyValue("CsWinRTIncludes", $"{csWinRTIncludesValue}{delimiter}{projectName}"); | ||
|
ujjwalchadha marked this conversation as resolved.
Outdated
|
||
|
|
||
| _logger.LogInformation(string.Format(CsWinRTLogMessage, projectName)); | ||
| } | ||
| } | ||
|
|
||
| projectFile.AddItem(new ProjectItemDescriptor(ProjectItemType.Compile) { Remove = "App.xaml.old.cs" }); | ||
| projectFile.AddItem(new ProjectItemDescriptor(ProjectItemType.None) { Include = "App.xaml.old.cs" }); | ||
| projectFile.RemoveItem(new ProjectItemDescriptor(ProjectItemType.Content) { Include = "Properties\\Default.rd.xml" }); | ||
|
|
@@ -85,6 +104,20 @@ public async Task<IUpdaterResult> ApplyAsync(IUpgradeContext context, ImmutableA | |
| new List<string>()); | ||
| } | ||
|
|
||
| private string ParseProjectNameWithExtension(string projectReference, string extension) | ||
|
ujjwalchadha marked this conversation as resolved.
|
||
| { | ||
| var index = projectReference.IndexOf(".vcxproj"); | ||
| index--; | ||
| StringBuilder sb = new StringBuilder(); | ||
|
ujjwalchadha marked this conversation as resolved.
|
||
| while (index > -1 && char.IsLetterOrDigit(projectReference[index])) | ||
| { | ||
| sb.Append(projectReference[index]); | ||
| index--; | ||
| } | ||
|
|
||
| return new string(sb.ToString().Reverse().ToArray()); | ||
| } | ||
|
|
||
| public async Task<IUpdaterResult> IsApplicableAsync(IUpgradeContext context, ImmutableArray<IProject> inputs, CancellationToken token) | ||
| { | ||
| await Task.Yield(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.