.netmauixunitmaui-windowsnet-maui

Missing "Platforms" folder when setting up a .NET MAUI project for xUnit testing


The problem is at follows. I'm working on my Bachelor's degree project in MAUI and I have to do some unit tests. I looked up online and found several tutorials that show the modification of the .csproj file. For reference I will provide this video from the MAUI Community Standup because it was the most recent I could find on the topic.

After the modification of the .csproj file, I'm getting errors about the "Platforms" folder missing from the project. In addition, the errors come from net8.0, even when I switch to net8.0-windows10.0.19041.0 from the drop down.

I currently do have some code that is Windows specific and I'm not sure if it is related. On a new project I was able to successfully perform the changes and run tests.

Thanks in advance.

Update 1: Since I noticed a user still asked for what was configured in the .csproj, the following line:

<TargetFrameworks>net8.0</TargetFrameworks>
...
<OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType>

Do notice that I don't add Android, iOS and Mac. I currently just don't have the type to write the platform specific code for these platforms.

Update 2: By using the preprocessor directive #if !NET8_0 , I was able to remove the errors and even run a blank test. But now the project crashes on startup because it can't find the services for windows, even when the directive specifically declares that it shouldn't be just a net8.0 project.


Solution

  • The problem was with platform specific code. In my example, I had some NFC functionality for Windows. Wrapping all the segments in #if WINDOWS solved the issue.