Skip to content

Commit b0d55de

Browse files
committed
fix: Show error message when incompatible winappsdk to net7.0 with uno is found
1 parent 4953b16 commit b0d55de

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

build/uno.winui.common.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
Condition="'$(PkgUno_UI)'!='' and '$(PkgUno_WinUI)'!=''" />
2727
</Target>
2828

29+
<!--
30+
Include a marker for _FindInvalidWinAppSDKUnoPlatformReference to determine if a net7.0-only project is referenced
31+
from a WinAppSDK project.
32+
-->
33+
<Target Name="_UnoUpdateAdditionalProperties" BeforeTargets="GetTargetFrameworksWithPlatformForSingleTargetFramework">
34+
<ItemGroup>
35+
<AdditionalTargetFrameworkInfoProperty Include="_IsUnoPlatform" />
36+
</ItemGroup>
37+
</Target>
38+
2939
<Import Project="$(SourceGeneratorBasePath)Uno.UI.SourceGenerators.props" />
3040
<Import Project="$(UnoUIMSBuildTasksTargetPath)Uno.UI.Tasks.targets" />
3141

build/uno.winui.winappsdk.targets

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,28 @@
6464

6565
</Target>
6666

67+
<Target Name="_FindInvalidWinAppSDKUnoPlatformReference"
68+
BeforeTargets="ResolveAssemblyReferences"
69+
Condition="'$(UnoDisableUNOB0002Validation)'==''">
70+
71+
<PropertyGroup>
72+
<_UnoPlatformProperty>_IsUnoPlatform=true</_UnoPlatformProperty>
73+
</PropertyGroup>
74+
75+
<!--
76+
Determine if any ProjectReference contains AdditionalProperties which contains _IsUnoPlatform, a property
77+
defined only when WinAppSDK is not included.
78+
79+
This scenario can happen when a WinAppSDK project is referencing a net7.0-only project which contains a reference to
80+
Uno.WinUI, which is not compatible with WinAppSDK. Fixing this requires adding a netX.0-windows10.x target to the project.
81+
-->
82+
<Error Code="UNOB0002"
83+
HelpLink="https://aka.platform.uno/UNOB0002"
84+
Text="Project %(TargetPathWithTargetPlatformMoniker.MSBuildSourceProjectFile) contains a reference to Uno Platform but does not contain a WinAppSDK compatible target framework. https://aka.platform.uno/UNOB0002"
85+
Condition="
86+
'%(TargetPathWithTargetPlatformMoniker.MSBuildSourceProjectFile)'!=''
87+
and '%(TargetPathWithTargetPlatformMoniker.AdditionalPropertiesFromProject)'!=''
88+
and '%(TargetPathWithTargetPlatformMoniker.AdditionalPropertiesFromProject)'!='%(TargetPathWithTargetPlatformMoniker.AdditionalPropertiesFromProject.Replace($(_UnoPlatformProperty),))'" />
89+
</Target>
90+
6791
</Project>

doc/articles/get-started-dotnet-new.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
uid: GetStarted.dotnet-new
3+
---
14
# dotnet new templates for Uno Platform
25

36
The Uno Platform provides a set of command-line templates to create cross-platform applications.

doc/articles/guides/how-to-create-control-libraries.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
uid: Guide.HowTo.Create-Control-Library
3+
---
14
# How to Create Control Libraries
25

36
Uno Platform, like WinUI and UWP, supports Control Libraries. Control Libraries are a way to reuse UI components across multiple projects, either inside the solution or by using NuGet to distribute to other projects.

doc/articles/uno-build-error-codes.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
uid: Build.Solution.error-codes
3+
---
4+
# Uno Build error codes
5+
6+
## UNOB0001: Cannot build with both Uno.WinUI and Uno.UI NuGet packages referenced
7+
8+
This error code means that a project has determined what both `Uno.WinUI` and `Uno.UI` packages are referenced.
9+
10+
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 which is incompatible with your current project's configuration.
11+
12+
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.
13+
14+
## UNOB0002: Project XX contains a reference to Uno Platform but does not contain a WinAppSDK compatible target framework.
15+
16+
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.
17+
18+
This can happen if a project contains only a `net7.0` TargetFramework and has a NuGet reference to `Uno.WinUI`.
19+
20+
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).

0 commit comments

Comments
 (0)