dotnet build not finding Xamarin - xamarin

When running dotnet build in my project, I have the following error:
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.Android/My.Company.Toolkit.Platform.Android.csproj(91,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/Android/Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.
/path/to/repo/Toolkit/My.Company.Toolkit.Platform.iOS/My.Company.Toolkit.Platform.iOS.csproj(195,3): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.102//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.
I confirm that /usr/local/share/dotnet/sdk/7.0.102/Xamarin/iOS/Xamarin.iOS.CSharp.targets does not exist.
But I don't know how to install it there.
The reference to Xamarin is defined in the csproj like this <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />.
When I build from Visual Studio I have no issues. And if I try to re-install Xamarin, it says it is already installed.
I am on MacOS.
[UPDATE]
I uninstalled everything (Visual Studio, SDKs/Runtime, dotnet, etc).
Installed just Visual Studio 2022 for Mac.
➜ ~ dotnet --info
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480
Runtime Environment:
OS Name: Mac OS X
OS Version: 13.1
OS Platform: Darwin
RID: osx.13-arm64
Base Path: /usr/local/share/dotnet/sdk/7.0.102/
Host:
Version: 7.0.2
Architecture: arm64
Commit: d037e070eb
.NET SDKs installed:
6.0.405 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Now if I try to build the project in the terminal I still have the same error. But if I try to build it from Visual Studio I have a different error.
I have this error in the build output
Target RazorGenerateComponentDeclaration:
/usr/local/share/dotnet/dotnet exec "/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll" generate
-s
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/_Imports.razor
-r
_Imports.razor
-o
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web/obj/Debug/netstandard2.1/RazorDeclaration/_Imports.razor.g.cs
-k
component
-p
/Users/redacted/Developer/repositories/bcee/Toolkit/MyCompany.Toolkit.Platform.Web
-t
obj/Debug/netstandard2.1/MyCompany.Toolkit.Platform.Web.RazorComponents.declaration.json
-v
3.0
-c
Default
--root-namespace
MyCompany.Toolkit.Web
--csharp-language-version
8.0
--generate-declaration
The application to execute does not exist: '/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/../../tools/netcoreapp3.0/rzc.dll'
/Users/redacted/Library/Caches/VisualStudio/17.0/MSBuild/36265_3/Sdks/Microsoft.NET.Sdk.Razor/build/netstandard2.0/Microsoft.NET.Sdk.Razor.Component.targets(106,5): error : rzc generate exited with code 129.
Done building target "RazorGenerateComponentDeclaration" in project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.
Done building project "MyCompany.Toolkit.Platform.Web.csproj" -- FAILED.
Build FAILED.
The tools directory does not exists.

At fisrt, you said:
When I build from Visual Studio I have no issues.
The cause should be when you build from the Visual Studio. The framework your project used is .netstandard 2.0. You can check the project.csproj file and the SDK in the /usr/local/share/dotnet/sdk.
In addition, you can check this case which has the similar error as yours. According to it, if the .net version is not compatible with the xamarin will also get this error. dotnet/sdk/7.0.102 should be the .net 7 which is compatible with the .net maui not the xamarin. So you can't use the dotnet build the project.
You can try to find the right value of the MSBuildExtensionsPath and set it in the android and ios .csproj file according to this case which is about set the project's MSBuildExtensionsPath.
Finally, you can try the solution in this case which has the same error message.

The Xamarin tool chain was built upon Mono, so everything you triggered in VS for Mac is kindly processed by MSBuild for Mono (at Mac terminal you can use msbuild --version to learn more).
dotnet build, however, was designed exclusively for .NET Core based projects, so by default it won't be able to handle Xamarin projects, but only .NET MAUI.
As legacy Xamarin projects are going away soon, you should start to migrate to MAUI as soon as you can,
https://dotnet.microsoft.com/en-us/platform/support/policy/xamarin

Related

The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found

I am using Visual Studio 2019 Version 16.3.7. I assume it is the latest update.
When I try to compile a basic .NET Core 2.2 console application:
...I get the following error:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
- The following frameworks were found:
1.0.1 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.11 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
3.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The .NET Core frameworks can be found at:
- https://aka.ms/dotnet-download .
My understanding is that .NET Core 3.0 is backward compatible. Why Visual Studio installer installed all versions of .NET Core except 2.2?
How do I solve this problem?
For whatever reason, .NET Core 2.2 is not installed by the ".NET Core cross-platform development" workload.
Open up the Visual Studio installer then go to the "Individual components" tab and you can install it from there:
In my case was missing x86 .NET Core 2.2.x Platform SDK (Visual Studio .NET 16.4 + .NET Core 3.1 SDK ; xUnit Test Project).
You can try this:
Exist directory 2.2.x in: C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App ?
When no, try Download latest 2.2.x SDK for x86 platform from this URL: https://dotnet.microsoft.com/download/dotnet-core/2.2
Install and try ...
For more info about installed SDK and Runtime you can use command: dotnet --info
For those trying to deploy a file to a non-developer machine and you see this error, use the Project -> Publish option with a Folder Profile and update the settings to be "Deployment mode: Self-contained". Then "Publish" it.
This will embed the runtime into the .exe, making it much larger, but also simple to "just work" on a client machine.
You can install x86 .NET Core 2.2.x Platform SDK as #Martin said.
If you do not need x86 version like me, you can also set
<PlatformTarget>AnyCPU</PlatformTarget>
to
<PlatformTarget>x64</PlatformTarget>
in both main project and test project 's .csproj file
to avoid this problem.
Two options are to run the Visual Studio Update application to see if any missing requirements will be installed for you or to install the net core 2.2 SDK manually from https://dotnet.microsoft.com/download/dotnet-core/2.2 (or https://aka.ms/dotnet-download as mentioned in the error message).
.NET Core 2.2.0 is not supported anymore.
Waiting for the .NET 5

Visual Studio not recognizing installed Core SDKs

I have three versions of .NET Core installed on my machine:
However, both VS2017 and VS 2019 return the following error when I execute dotnet --version command:
PM> dotnet --version
dotnet : Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
I can create a solution targeting .NET Core but when I create a Console App targeting .NET Core, for example, the Debug button is labeled Attach instead of Start as usual, and Start Debugging and Start Without Debugging commands in the Debug menu are disabled.
What I tried so far:
Added "C:\ProgramFiles\dotnet" to system PATH variable.
Modified VS2019 using VS Installer.
Restarted several times.
I did have several other version of .NET Core but uninstalled them since I had no solutions targeting these versions and wanted to clean up.
I only left 2.2.300 and 3.0.100 and when I used VS Installer to modify VS2019 it added SDK 2.1.700.
Any ideas on how to resolve this issue without completely removing Visual Studio and installing from scratch?
Apparently x86 version(s) of .NET Core SDKs must be installed as well. After installing 3.0.100 x86 dotnet --version command works fine and I can build and debug .NET Core projects...

What determines whether my .net core uses .csproj or project.json

I've got a machine with .NET Core 1.1.0 1.0.0-preview2-1-003182 installed as well as VisualStudio 2017 RC. When I create a project using "dotnet new -t Console" it requires a project.json file. When I create a .NET Core ConsoleApp in Visual Studio 2017 it requires the .csproj for build configuration. What determines this? I'd like to have one or the other, preferably consistent .csproj since project.json is deprecated for future versions as far as I can tell.
VisualStudio 2017 RC won't seem to build a self-contained executable, so I revert to the command line to attempt a "dotnet publish -t win10-x64" whereby I get the error that there is no project.json. So, even if I have my .csproj configured to build an .exe, I can't just build it.
The version of .NET Core Tools is the reason:
.csproj is used starting from .NET Core Tools Preview 3
Note: Visual Studio 2017 RC installs .NET Core Tools Preview 3 (or even Preview 4 now).
project.json is used in previous versions.
If you want to know with version of .NET Core Tools is used then go to root project folder and run next command:
dotnet --info
Possible output:
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
If you have more then one version of .NET Core Tools on your machine, you can directly specify with version should be used for your project by global.json. Create (if not exists) this file in root folder and add "sdk" section. For example for Tools Preview 2:
{
...
"sdk": { "version": "1.0.0-preview2-1-003177" }
}
Also you may use dotnet-migrate command to convert your project.json to .csproj

Visual Studio Preview for Mac 2017 .NET Core build error

When I try to run the .NET Core Project on last version of Visual Studio Preview for Mac, I get next error:
The specified framework 'Microsoft.NETCore.App', version '1.0.1' was not found.
- Check application dependencies and target a framework version installed at:
/usr/local/share/dotnet/shared/Microsoft.NETCore.App
- The following versions are installed:
1.1.0
- Alternatively, install the framework version '1.0.1'.
The application was terminated by a signal: SIGQUIT
WARNING: The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use Microsoft.NETCore.App 1.0.0 or newer. This may be expected if the target process did not run .NET code.
I opened Project Settings, and in the 'Target Framework' Dropdown there is no .NETCoreApp 1.1, only 1.0 (which is not installed)
What should I change in project or Studio configs for project to run successfully? Or I just must wait for VS update?
Thanks for response.
Update your nuget packages i.e Project -> Update Nuget Packages. The Microsoft.NetCore.App package is out of date.
Step 1: setup .net Core
--> https://www.microsoft.com/net/core#macos
--> if you get donet new command not found, try this: ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/
Step 2: update packages

Xamarin xbuild: Warning when building .shproj-Files

Given a Xamarin Studio solution containing a shared project, and an iOS project referencing the shared project. When building the solution with xbuild like this:
xbuild /p:Configuration=Release /p:Platform="iPhone" /target:Build GridVisibilityBug.sln
The build contains several warnings like the following:
/Users/work/.../GridVisibilityBug/GridVisibilityBug.shproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/VisualStudio/v/CodeSharing/Microsoft.CodeSharing.Common.Default.props, to import. Ignoring.
/Users/work/.../GridVisibilityBug/GridVisibilityBug.shproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/VisualStudio/v/CodeSharing/Microsoft.CodeSharing.Common.props, to import. Ignoring.
/Users/work/.../GridVisibilityBug/GridVisibilityBug.shproj: warning : Could not find project file /Library/Frameworks/Mono.framework/External/xbuild/Microsoft/VisualStudio/v/CodeSharing/Microsoft.CodeSharing.CSharp.targets, to import. Ignoring.
When building just the csproj, I do not get the warnings (just building the csproj is not desirable however, because the solution contains other projects):
xbuild /p:Configuration=Release /p:Platform="iPhone" /target:Build iOS/GridVisibilityBug.iOS.csproj
When building with the deprecated mdtool, I do not get the warnings either:
/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool -v build "--configuration:Release|iPhone" GridVisibilityBug.sln
How should I rate this warning? Is it harmless, or is there something serious missing? Can I fix the warning (the referenced files really are not located at the given location)?
I'm using older Xamarin version, due to the project being in a longer release period:
Xamarin Studio
Version 5.10.2 (build 56)
Installation UUID: 09335063-06f8-425b-8e56-2cdecfb3c10c
Runtime:
Mono 4.2.2 (explicit/996df3c)
GTK+ 2.24.23 (Raleigh theme)
Apple Developer Tools
Xcode 7.3.1 (10188.1)
Build 7D1014
Xamarin.iOS
Version: 9.4.1.25 (Business Edition)
Hash: 962a050
Branch: master
Build date: 2016-01-29 16:59:11-0500
Operating System
Mac OS X 10.11.6
Darwin Stephans-MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0
Mon Aug 29 20:21:34 PDT 2016
root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
Edit:
The initial example should now be more clear. The example project I used is the one attached to https://bugzilla.xamarin.com/show_bug.cgi?id=46501. It was created with the Xamarion Studio / Xamarin iOS versions mentioned above.
I've also been able to reproduce the problem on the system with newer Xamarin versions. Workflow: Create a new solution via File->New->Solution->Xamarin.Forms App, select shared project and iOS only. Then build the solution with the xbuild command mentioned above. Versions on this system: Xamarin Studio 6.1.1, Mono 4.6.1, Xamarin iOS 10.0.1.8, Mac OS X 10.11.6.
Edit 2:
The shproj xml indeed imports the files mentioned in the warning, and the files are not present on our systems. At least not in the expected location. The build itself works though. My main question is if these warnings can be ignored safely.

Resources