I have been working on tool that is done using NET MAUI. Now I would like to automate Windows UI, but I can't figure out how to do that. I have tried to download FlaUI NuGet, but can't get it working as it requires project to be Net7.0-windows. So I have created new project with reference to Net7.0-windows, but then my references in Net Maui get corrupted.
MauiApp1.csproj (project):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>MauiApp1</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Display name -->
<ApplicationTitle>MauiApp1</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.companyname.mauiapp1</ApplicationId>
<ApplicationIdGuid>67771146-3ce8-452f-860b-3669d8a9e4a0</ApplicationIdGuid>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>
</Project>
Project ClassLibrary1.csproj (project):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FlaUI.Core" Version="4.0.0" />
<PackageReference Include="FlaUI.UIA3" Version="4.0.0" />
</ItemGroup>
</Project>
Currently if:
I get following errors:
My question is How to reference ClassLibrary1.csproj in MauiApp1.csproj in NET MAUI? Is there some way to get this setup working?


If your
ClassLibrary1project going to support all platforms then you should add this lines to yourClassLibrary1.cspojfile too.If your
ClassLibrary1project going to support just windows then you can do two things;If your MAUI project just going to run on windows only, on your
MauiApp1.csprojfile you should delete these lines;If your MAUI App going to support other platforms at the same time, you should add your platform specific libraries separate. I am using this for my multiplatform MAUI apps.
Solution Explorer > Your MAUI Project > Dependencies > Right Click Your Platform > Add referencethen open your
MauiApp1.csprojfile, find your reference and add an condition to your reference. Your reference should be like this at the end;EXAMPLE
I've made an example. I created a MAUI project named
MauiApp1and a class library namedMauiLib1.MauiLib1only supports Windows platform andMauiApp1supports all platforms. I've addedMauiLib1toMauiApp1but for only Windows platform. Required.csprojfiles and platform specific codes can be seen below.MauiApp1.csprojMauiLib1.csprojA simple class in
MauiLib1project. So we can make a test.Changed
MauiApp1project's defaultMainPage.xaml.cscode a little bit. Here you can see Windows specific codes. Without these conditions your app will crash. Because there will not be a reference for that platform.After 3 clicks, you'll see our string in the button and here it's solution explorer's screenshot. As you can see reference added for windows only.
Note 1
Don't forget to change your current platform on the Visual Studio. It's very important. Otherwise, your platform specific codes will not be compiled.
Note 2
I deleted the parts unrelated to the question from the code. So everyone can see clearly what I've changed.
Note 3
If your library supports more than one platform you can add more conditions to your reference in the
.csprojfile.