Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface IProject

IEnumerable<IProject> ProjectReferences { get; }

public IEnumerable<string> AllProjectReferences { get; }
Comment thread
ujjwalchadha marked this conversation as resolved.
Outdated

IEnumerable<Reference> FrameworkReferences { get; }

INuGetReferences NuGetReferences { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public MSBuildProject(

public string Id => Context.SolutionInfo.GetProjectId(FileInfo.FullName);

public IEnumerable<string> AllProjectReferences => GetRoslynProject().AllProjectReferences.Select(projRef => projRef.ProjectId.ToString());
Comment thread
brandonh-msft marked this conversation as resolved.
Outdated

public IEnumerable<IProject> ProjectReferences => GetRoslynProject().ProjectReferences.Select(p =>
{
var project = Context.Workspace.CurrentSolution.GetProject(p.ProjectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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" +
Comment thread
ujjwalchadha marked this conversation as resolved.
Outdated
"If your project assembly name differs from {0}, update this value with the assembly name.\n" +
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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/";
Comment thread
ujjwalchadha marked this conversation as resolved.
Outdated

public string Id => typeof(WinUIPropertiesUpdater).FullName;

public string Title => "Update WinUI Project Properties";
Expand Down Expand Up @@ -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;
Comment thread
ujjwalchadha marked this conversation as resolved.
Outdated
var delimiter = csWinRTIncludesValue.Trim().Length == 0 || csWinRTIncludesValue.EndsWith(";") ? string.Empty : ";";
projectFile.SetPropertyValue("CsWinRTIncludes", $"{csWinRTIncludesValue}{delimiter}{projectName}");
Comment thread
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" });
Expand All @@ -85,6 +104,20 @@ public async Task<IUpdaterResult> ApplyAsync(IUpgradeContext context, ImmutableA
new List<string>());
}

private string ParseProjectNameWithExtension(string projectReference, string extension)
Comment thread
ujjwalchadha marked this conversation as resolved.
{
var index = projectReference.IndexOf(".vcxproj");
index--;
StringBuilder sb = new StringBuilder();
Comment thread
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.DotNet.UpgradeAssistant.Dependencies;
Expand All @@ -18,6 +19,9 @@ internal class WinUIReferenceAnalyzer : IDependencyAnalyzer
{
public string Name => "Windows App SDK package analysis";

private const string CsWinRTPackageName = "Microsoft.Windows.CsWinRT";
private const string CsWinRTVersion = "1.6.4";

private readonly IPackageLoader _packageLoader;
private readonly ILogger _logger;

Expand All @@ -34,6 +38,13 @@ public async Task AnalyzeAsync(IProject project, IDependencyAnalysisState state,
return;
}

if (project.AllProjectReferences.Any(id => id.Contains(".vcxproj")))
{
var newPackage = new NuGetReference(CsWinRTPackageName, CsWinRTVersion);
state.Packages.Add(newPackage,
new OperationDetails() { Risk = BuildBreakRisk.Medium, Details = ImmutableList.Create<string>(newPackage.Name) });
}

foreach (var package in state.Packages)
{
if (package.Name.StartsWith("Microsoft.Toolkit", StringComparison.Ordinal))
Expand Down