dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

Unable to build project using latest .NET sdk (Xamarin forms) #33705

Open apigee-impexp opened 1 year ago

apigee-impexp commented 1 year ago

Describe the bug

Visual Studio for Mac updated and also .NET SDK and runtime were also updated. Unfortunately, we are not able to build our project anymore (Android & iOS). We are encountering error in one of our project in the solution that is a.NET Portable (PCL 4.5 - Profile 259).

Error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.304/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.304/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets" is correct, and that the file exists on disk

To Reproduce

Use Visual Studio 2022 for Mac latest version

Exceptions (if any)

Further technical details

Runtime Environment: OS Name: Mac OS X OS Version: 13.4 OS Platform: Darwin RID: osx.13-arm64 Base Path: /usr/local/share/dotnet/sdk/7.0.304/

Host: Version: 7.0.7 Architecture: arm64 Commit: 5b20af47d9

.NET SDKs installed: 6.0.410 [/usr/local/share/dotnet/sdk] 7.0.304 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: x64 [/usr/local/share/dotnet/x64] registered at [/etc/dotnet/install_location_x64]

Environment variables: Not set

global.json file: Not found

PavlosMavris commented 1 year ago

I got the same error. Any lucky on resolving this?

apigee-impexp commented 1 year ago

I got the same error. Any lucky on resolving this?

unfortunately, no luck in resolving this issue. I hope someone can give us a fix.

LGFox commented 1 year ago

I had the same problem on Visual Studio for Mac 17.6 (build 1575).

I did not update any nuget packages or project configuration, only the IDE. I guess this messed up my build. It showed the same error as in the topic starter:

Error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.304/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.304/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets" is correct, and that the file exists on disk

When I tried msbuild from a console, it showed a different error. Same error was displayed when I tried JetBrains Rider:

error XA1032: Failed to resolve 'System.Net.Http.HttpClientHandler' from 'Mono.Android'. Please check your `AndroidHttpClientHandlerType` setting.

Then I followed this advice on stackoverflow, and it helped me to fix the build for JetBrains Rider. It still does not work for MS VS with the same error as in the topic starter.

P.S. JetBrains rules in the world of IDEs. Microsoft should just buy JetBrains, as it bought Github years ago. ๐Ÿ˜„ I can only image what "coding beasts" work at JetBrains. ๐Ÿ˜Ž

apigee-impexp commented 1 year ago

I had the same problem on Visual Studio for Mac 17.6 (build 1575).

I did not update any nuget packages or project configuration, only the IDE. I guess this messed up my build. It showed the same error as in the topic starter:

Error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.304/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.304/Microsoft/Portable/v4.5/Microsoft.Portable.CSharp.targets" is correct, and that the file exists on disk

When I tried msbuild from a console, it showed a different error. Same error was displayed when I tried JetBrains Rider:

error XA1032: Failed to resolve 'System.Net.Http.HttpClientHandler' from 'Mono.Android'. Please check your AndroidHttpClientHandlerType setting.

Then I followed this advice on stackoverflow, and it helped me to fix the build for JetBrains Rider. It still does not work for MS VS with the same error as in the topic starter.

P.S. JetBrains rules in the world of IDEs. Microsoft should just buy JetBrains, as it bought Github years ago. ๐Ÿ˜„ I can only image what "coding beasts" work at JetBrains. ๐Ÿ˜Ž

I tried the fix you mentioned but I am still encountering the issue.

LGFox commented 1 year ago

I tried the fix you mentioned but I am still encountering the issue.

Yes, as I said, that fix did not address the issue for MS VS. It only worked for JetBrains Rider.

PavlosMavris commented 1 year ago

I've managed to fix the issue. What worked for me was to set my "core" project to build with MSBuild at Mono.

You can find this in the project Properties->Build->General, there is a checkbox for "Build with MSBuild on Mono", Make sure it is checked.

Hopefully, this will help others too.

Note: I'm working on Xamarin Android and Xamarin iOS, not Xamarin Forms.

cjosepha commented 1 year ago

I've managed to fix the issue. What worked for me was to set my "core" project to build with MSBuild at Mono.

You can find this in the project Properties->Build->General, there is a checkbox for "Build with MSBuild on Mono", Make sure it is checked.

Hopefully, this will help others too.

Note: I'm working on Xamarin Android and Xamarin iOS, not Xamarin Forms.

I had the same issue, and actually setting "Build with MSBuild on Mono" on the Xamarin Forms project fixed it. In my Solution, this option was set on the Xamarin Android and Xamarin iOS projects, but not on the Xamarin Forms one.

d1hawkins commented 1 year ago

I've managed to fix the issue. What worked for me was to set my "core" project to build with MSBuild at Mono. You can find this in the project Properties->Build->General, there is a checkbox for "Build with MSBuild on Mono", Make sure it is checked. Hopefully, this will help others too. Note: I'm working on Xamarin Android and Xamarin iOS, not Xamarin Forms.

I had the same issue, and actually setting "Build with MSBuild on Mono" on the Xamarin Forms project fixed it. In my Solution, this option was set on the Xamarin Android and Xamarin iOS projects, but not on the Xamarin Forms one.

The same worked for me as well