Skip to content

Commit

Permalink
fix(uap): Fix generators should not run under uap builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jan 10, 2023
1 parent 535affc commit 26c6772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@ public class PlatformHelper
{
public static bool IsValidPlatform(GeneratorExecutionContext context)
{
var evaluatedValue = context.GetMSBuildPropertyValue("TargetPlatformIdentifier");
var windowsAppSDKWinUI = context.GetMSBuildPropertyValue("WindowsAppSDKWinUI");
var projectTypeGuids = context.GetMSBuildPropertyValue("ProjectTypeGuidsProperty");

var isUAP = evaluatedValue?.Equals("UAP", StringComparison.OrdinalIgnoreCase) ?? false;

// Those two checks are now required since VS 16.9 which enables source generators by default
// and the uno targets files are not present for uap targets.
var isWindowsRuntimeApplicationOutput = context.Compilation.Options.OutputKind == OutputKind.WindowsRuntimeApplication;
var isWindowsRuntimeMetadataOutput = context.Compilation.Options.OutputKind == OutputKind.WindowsRuntimeMetadata;

var isWinAppSDK = windowsAppSDKWinUI?.Equals("True", StringComparison.OrdinalIgnoreCase) ?? false;
var isNetCoreDesktop = projectTypeGuids?.Equals("{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", StringComparison.OrdinalIgnoreCase) ?? false;

return !isUAP
&& !isWinAppSDK
&& !isNetCoreDesktop
return !isNetCoreDesktop
&& !isWindowsRuntimeMetadataOutput
&& !isWindowsRuntimeApplicationOutput;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@

<ItemGroup Condition="'$(WindowsAppSDKWinUI)'!='true'">
<CompilerVisibleProperty Include="XamlSourceGeneratorTracingFolder" />
<CompilerVisibleProperty Include="TargetPlatformIdentifier" />
<CompilerVisibleProperty Include="TargetFramework" />
<CompilerVisibleProperty Include="ProjectTypeGuidsProperty" />
<CompilerVisibleProperty Include="MSBuildProjectFullPath" />
Expand Down Expand Up @@ -186,7 +185,7 @@
<ExcludeXamlNamespaces Condition="'$(XamarinProjectType)'=='skia'" Include="macos" />
<ExcludeXamlNamespaces Condition="'$(XamarinProjectType)'=='skia'" Include="not_skia" />

<!--
<!--
Those namespaces are to be *included* from the code generation,
regardless of their presence in the Ignorable section of a Xaml file.
-->
Expand Down Expand Up @@ -363,9 +362,9 @@
</ItemGroup>

<Target Name="_IncludeXamlFiles" BeforeTargets="_UnoSourceGenerator" DependsOnTargets="_FillSourceGeneratorItemGroups">
<!--
This group is created as part of a target to ensure the
capture of target-defined Pages
<!--
This group is created as part of a target to ensure the
capture of target-defined Pages
-->
<ItemGroup>
<SourceGeneratorInput Include="@(Page);@(ApplicationDefinition);@(UnoPage);@(UnoApplicationDefinition)" />
Expand Down Expand Up @@ -451,10 +450,9 @@
Text="Uno.UI is using Uno.SourceGenerators" />
</Target>

<Target Name="_RemoveRoslynUnoSourceGeneration" BeforeTargets="CoreCompile" Condition="'$(UnoUIUseRoslynSourceGenerators)'=='false' or '$(WindowsAppSDKWinUI)'=='true'">
<!---
If the users explicitly disables Roslyn source generation, remove the analyzer item which is automatically added by Nuget.
-->
<Target Name="_RemoveRoslynUnoSourceGeneration" BeforeTargets="CoreCompile" Condition="'$(UnoUIUseRoslynSourceGenerators)'=='false' or '$(WindowsAppSDKWinUI)'=='true' or $(TargetFramework.StartsWith('uap10.0'))">
<!--- If the users explicitly disables Roslyn source generation, remove the analyzer item which is automatically added by NuGet. -->
<!-- Additionally, if this is a Windows build, remove the analyzer item for the generators. -->
<ItemGroup>
<_AnalyzerToRemove Include="@(Analyzer)" Condition="'%(FileName)'=='Uno.UI.SourceGenerators'" />
<Analyzer Remove="@(_AnalyzerToRemove)"/>
Expand Down

0 comments on commit 26c6772

Please sign in to comment.