-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11370 from unoplatform/dev/jela/winappsdk-mix
fix: Show an error message when incompatible winappsdk to net7.0 with uno is found
- Loading branch information
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
uid: Build.Solution.error-codes | ||
--- | ||
# Uno Build error codes | ||
|
||
## UNOB0001: Cannot build with both Uno.WinUI and Uno.UI NuGet packages referenced | ||
|
||
This error code means that a project has determined what both `Uno.WinUI` and `Uno.UI` packages are referenced. | ||
|
||
To fix this issue, you may be explicitly referencing `Uno.UI` and `Uno.WinUI` in your `csproj`, or you may be referencing a NuGet package that is incompatible with your current project's configuration. | ||
|
||
For instance, if your project references `Uno.WinUI`, and you try to reference `SkiaSharp.View.Uno`, you will get this error. To fix it, you'll need to reference `SkiaSharp.View.Uno.WinUI` instead. | ||
|
||
## UNOB0002: Project XX contains a reference to Uno Platform but does not contain a WinAppSDK compatible target framework. | ||
|
||
This error code means that a WinAppSDK project is referencing a project in your solution which is not providing a `net6.0-windows10.xx` TargetFramework. | ||
|
||
This can happen if a project contains only a `net7.0` TargetFramework and has a NuGet reference to `Uno.WinUI`. | ||
|
||
To fix this, it is best to start from a `Cross Platform Library` project template provided by the Uno Platform [visual studio extension](xref:Guide.HowTo.Create-Control-Library), or using [`dotnet new`](xref:GetStarted.dotnet-new). |
73 changes: 73 additions & 0 deletions
73
src/SourceGenerators/Uno.UI.Tasks/WinAppSDKValidations/ValidateWinAppSDKReferences.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Uno.UI.Tasks.WinAppSDKValidations; | ||
|
||
/// <summary> | ||
/// A task used to merge linker definition files and embed the result in an assembly | ||
/// </summary> | ||
public class ValidateWinAppSDKReferences_v0 : Microsoft.Build.Utilities.Task | ||
{ | ||
[Required] | ||
public ITaskItem[] ReferencedProjects { get; set; } = Array.Empty<ITaskItem>(); | ||
|
||
public override bool Execute() | ||
{ | ||
foreach (var project in ReferencedProjects) | ||
{ | ||
string nearestTargetFramework = project.GetMetadata("NearestTargetFramework"); | ||
|
||
if (string.IsNullOrEmpty(nearestTargetFramework) || !(project.GetMetadata("AdditionalPropertiesFromProject") is { Length: > 0 })) | ||
{ | ||
// Referenced project doesn't have the right metadata. This may be because it's a different project type (C++, for example) | ||
// In this case just skip the checks | ||
continue; | ||
} | ||
|
||
var additionalPropertiesXml = XElement.Parse(project.GetMetadata("AdditionalPropertiesFromProject")); | ||
|
||
XElement targetFrameworkElement = | ||
additionalPropertiesXml | ||
.Elements() | ||
.Where(el => el.HasAttributes && el.FirstAttribute.Value.Equals(nearestTargetFramework)) | ||
.Single(); | ||
|
||
Dictionary<string, string> projectAdditionalProperties = new(StringComparer.OrdinalIgnoreCase); | ||
|
||
if (targetFrameworkElement is not null) | ||
{ | ||
foreach (var propertyElement in targetFrameworkElement.Elements()) | ||
{ | ||
projectAdditionalProperties[propertyElement.Name.LocalName] = propertyElement.Value; | ||
} | ||
|
||
if (projectAdditionalProperties.TryGetValue("_IsUnoPlatform", out var isUnoPlatformValue) | ||
&& bool.TryParse(isUnoPlatformValue, out bool isUnoPlatform) | ||
&& isUnoPlatform) | ||
{ | ||
Log.LogError( | ||
subcategory: null, | ||
errorCode: "UNOB0002", | ||
helpKeyword: null, | ||
file: null, | ||
lineNumber: 0, | ||
columnNumber: 0, | ||
endLineNumber: 0, | ||
endColumnNumber: 0, | ||
message: "Project {0} contains a reference to Uno Platform but does not contain a WinAppSDK compatible target framework. https://aka.platform.uno/UNOB0002", | ||
messageArgs: project.ItemSpec | ||
); | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |