microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
228 stars 12 forks source link

[BUG] .Net can't recognize '*.jar' as any file with extension .jar - Can't Find *.jar file when building .NET MAUI project #830

Closed AxisSoftwareDevelopment closed 9 months ago

AxisSoftwareDevelopment commented 10 months ago

Describe the Issue

Update: I found the root of the issue (although I don't know how to solve it/work around it properly), I posted it on the first comment, you still are free to read this post to know the context of how I got to this issue, thanks in advance for any help!

Im trying to migrate a project from Windows(VS2022) to Mac(VSCode). This project works on .net 7 version.

I followed the guide on the .net maui documentation to get the environment running on Mac/VSCode, and I'm able to get a test project running, but when trying to debug my project, I get this error:

Executing task: dotnet build -t:Run -p:Configuration=Debug -f net7.0-android -p:AdbTarget=-s%20emulator-5554 -p:AndroidAttachDebugger=true -p:AndroidSdbTargetPort=50606 -p:AndroidSdbHostPort=50606 -p:AndroidSdkDirectory='/Users/axissoftwaredevelopment/Library/Android/sdk' -p:JavaSdkDirectory='/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home' /Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj 

MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028: System.IO.FileNotFoundException: Could not find file '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.j2objc.annotations/1.3.0.1/jar/*.jar'. [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028: File name: '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.j2objc.annotations/1.3.0.1/jar/*.jar' [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.IO.FileInfo.get_Length() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.SizeAndContentFileComparer.GetHashCode(FileInfo obj) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.Add(T item) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Linq.Enumerable.DistinctIterator`1.MoveNext() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.DistinctFilesByContent(IEnumerable`1 filePaths) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Xamarin.Android.Tasks.CheckDuplicateJavaLibraries.RunTask() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]

Build FAILED.

/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028: System.IO.FileNotFoundException: Could not find file '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.j2objc.annotations/1.3.0.1/jar/*.jar'. [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028: File name: '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.j2objc.annotations/1.3.0.1/jar/*.jar' [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.IO.FileInfo.get_Length() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.SizeAndContentFileComparer.GetHashCode(FileInfo obj) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.Add(T item) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Linq.Enumerable.DistinctIterator`1.MoveNext() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.DistinctFilesByContent(IEnumerable`1 filePaths) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Xamarin.Android.Tasks.CheckDuplicateJavaLibraries.RunTask() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/33.0.95/tools/Xamarin.Android.Common.targets(852,3): error XACDJ7028:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net7.0-android]
    0 Warning(s)
    1 Error(s)

This is odd since the file DOES exist in the signaled path. I find it odd that building maui on VSCode creates a C: directory inside of my project, but when lookin in the finder app it is named just C/, idk if that could be the issue? something like its looking for C: but Mac can't handle punctuation marks on folder names? although on the VSCode explorer the folder is shown as C:, so idk to be honest.

Im kind of fishing for answers here, any help is welcome. Thanks in advance!

Steps To Reproduce

  1. Create a .net7 MAUI project from a Windows machine on VS2022 targeting android version 33.
  2. Move that project to a MacOS device on the VSCode MAUI environment.
  3. Try to build.

Expected Behavior

Be able to build the project

Environment Information

-macOS Sonoma. -M3 processor

AxisSoftwareDevelopment commented 10 months ago

It seems the issue lies in the fact that .net is searching for these files in the format of .../.../*.jar which it seems to not recognize. I proved this by creating a simple console app which just tries to read file and using both paths: with *.jar and with <specificFileName>.jar obviously doing so with the appropriate file names. My console app couldn't find the "*.jar" file.

When changing the name of the file on the error message attached above to *.jar, my build could pass from that point, but failed on the next .jar file validation, for the same reason:

Executing task: dotnet build -t:Run -p:Configuration=Debug -f net8.0-android -p:AdbTarget=-s%20emulator-5554 -p:AndroidAttachDebugger=true -p:AndroidSdbTargetPort=50364 -p:AndroidSdbHostPort=50364 -p:AndroidSdkDirectory='/Users/axissoftwaredevelopment/Library/Android/sdk' -p:JavaSdkDirectory='/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home' /Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj 

MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028: System.IO.FileNotFoundException: Could not find file '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.guava.failureaccess/1.0.1.7/jar/*.jar'. [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028: File name: '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.guava.failureaccess/1.0.1.7/jar/*.jar' [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.IO.FileInfo.get_Length() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.SizeAndContentFileComparer.GetHashCode(FileInfo obj) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.Add(T item) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Linq.Enumerable.DistinctIterator`1.MoveNext() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.DistinctFilesByContent(IEnumerable`1 filePaths) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Xamarin.Android.Tasks.CheckDuplicateJavaLibraries.RunTask() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]

Build FAILED.

/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028: System.IO.FileNotFoundException: Could not find file '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.guava.failureaccess/1.0.1.7/jar/*.jar'. [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028: File name: '/Users/axissoftwaredevelopment/Repos/Spots/Spots/C:/.ng/xamarin.google.guava.failureaccess/1.0.1.7/jar/*.jar' [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.IO.FileInfo.get_Length() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.SizeAndContentFileComparer.GetHashCode(FileInfo obj) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value, Int32& location) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Collections.Generic.HashSet`1.Add(T item) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Linq.Enumerable.DistinctIterator`1.MoveNext() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Xamarin.Android.Tasks.MonoAndroidHelper.DistinctFilesByContent(IEnumerable`1 filePaths) [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Xamarin.Android.Tasks.CheckDuplicateJavaLibraries.RunTask() [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/34.0.52/tools/Xamarin.Android.Common.targets(868,3): error XACDJ7028:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25 [/Users/axissoftwaredevelopment/Repos/Spots/Spots/Spots.csproj::TargetFramework=net8.0-android]
    0 Warning(s)
    1 Error(s)

So, I could go file by file, renaming them to *.jar so that the build can pass, but not only this seems pretty unsafe (since I myself don't know what these files do or are for) but probably whenever I try to reload my project or something like that, these changes might be overwritten (although it doesn't seem to be very often needed to run that command).

Is there a way to change how my build code looks for these paths? the error message points to an XML file as the root of the exception:

image

And I think the paths might be taken from the "@(AndroidJavaLibrary)" but I don't seem to be able to follow the thread to where these files could be hardcoded (if the are in the first place, if they are not, then all this is useless an my only workaround is to rename the files)

AxisSoftwareDevelopment commented 9 months ago

Turns out this was happening because I had this on my .csproj

        <PropertyGroup> 
        <RestorePackagesPath>C:\.ng</RestorePackagesPath> 
    </PropertyGroup> 

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-android|AnyCPU'"> 

This explains why the odd paths was being created, removing these lines allowed me to build my project properly. Still seems odd that I can't have these instruction to change where the nugget packages are saved, and more so considering that changing the names of the files in the nugget packages to *.jar allows the new save locations to work.

emaf commented 9 months ago

I think the problem is you are using Windows paths on macOS, which don't have the same meaning (specifically the volume). You could still specify a path where you want your packages to be restored using a relative path (i.e., ../.ng), or by using properties conditioned by OS and setting OS specific paths (i.e., ~/.ng for macOS and C:\.ng for Windows).

Something similar to:

<PropertyGroup> 
    <RestorePackagesPath Condition="('$(OS)' == 'Windows_NT')">C:\.ng</RestorePackagesPath> 
    <RestorePackagesPath Condition="('$(OS)' != 'Windows_NT')">~/.ng</RestorePackagesPath> 
</PropertyGroup> 

I'm closing this as it is not related to the MAUI extension for VS Code. If you need more help with this problem, please feel free to open an issue on the .NET MAUI SDK repo so folks from that team can help you: https://github.com/dotnet/maui/issues