Skip to content

Commit

Permalink
fix: Show error message when incompatible winappsdk to net7.0 with un…
Browse files Browse the repository at this point in the history
…o is found
  • Loading branch information
jeromelaban committed Feb 20, 2023
1 parent 4953b16 commit b0d55de
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build/uno.winui.common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
Condition="'$(PkgUno_UI)'!='' and '$(PkgUno_WinUI)'!=''" />
</Target>

<!--
Include a marker for _FindInvalidWinAppSDKUnoPlatformReference to determine if a net7.0-only project is referenced
from a WinAppSDK project.
-->
<Target Name="_UnoUpdateAdditionalProperties" BeforeTargets="GetTargetFrameworksWithPlatformForSingleTargetFramework">
<ItemGroup>
<AdditionalTargetFrameworkInfoProperty Include="_IsUnoPlatform" />
</ItemGroup>
</Target>

<Import Project="$(SourceGeneratorBasePath)Uno.UI.SourceGenerators.props" />
<Import Project="$(UnoUIMSBuildTasksTargetPath)Uno.UI.Tasks.targets" />

Expand Down
24 changes: 24 additions & 0 deletions build/uno.winui.winappsdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,28 @@

</Target>

<Target Name="_FindInvalidWinAppSDKUnoPlatformReference"
BeforeTargets="ResolveAssemblyReferences"
Condition="'$(UnoDisableUNOB0002Validation)'==''">

<PropertyGroup>
<_UnoPlatformProperty>_IsUnoPlatform=true</_UnoPlatformProperty>
</PropertyGroup>

<!--
Determine if any ProjectReference contains AdditionalProperties which contains _IsUnoPlatform, a property
defined only when WinAppSDK is not included.
This scenario can happen when a WinAppSDK project is referencing a net7.0-only project which contains a reference to
Uno.WinUI, which is not compatible with WinAppSDK. Fixing this requires adding a netX.0-windows10.x target to the project.
-->
<Error Code="UNOB0002"
HelpLink="https://aka.platform.uno/UNOB0002"
Text="Project %(TargetPathWithTargetPlatformMoniker.MSBuildSourceProjectFile) contains a reference to Uno Platform but does not contain a WinAppSDK compatible target framework. https://aka.platform.uno/UNOB0002"
Condition="
'%(TargetPathWithTargetPlatformMoniker.MSBuildSourceProjectFile)'!=''
and '%(TargetPathWithTargetPlatformMoniker.AdditionalPropertiesFromProject)'!=''
and '%(TargetPathWithTargetPlatformMoniker.AdditionalPropertiesFromProject)'!='%(TargetPathWithTargetPlatformMoniker.AdditionalPropertiesFromProject.Replace($(_UnoPlatformProperty),))'" />
</Target>

</Project>
3 changes: 3 additions & 0 deletions doc/articles/get-started-dotnet-new.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
uid: GetStarted.dotnet-new
---
# dotnet new templates for Uno Platform

The Uno Platform provides a set of command-line templates to create cross-platform applications.
Expand Down
3 changes: 3 additions & 0 deletions doc/articles/guides/how-to-create-control-libraries.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
uid: Guide.HowTo.Create-Control-Library
---
# How to Create Control Libraries

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.
Expand Down
20 changes: 20 additions & 0 deletions doc/articles/uno-build-error-codes.md
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 which 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).

0 comments on commit b0d55de

Please sign in to comment.