Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSB4226: The imported project "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/Mac/Xamarin.Mac.CSharp.targets" was not found. #9550

Closed
spouliot opened this issue Aug 31, 2020 · 22 comments
Assignees
Labels
bug If an issue is a bug or a pull request a bug fix macOS Issues affecting macOS
Milestone

Comments

@spouliot
Copy link
Contributor

Steps to Reproduce

  1. Install stable XM
  2. Build a new/existing project

Expected Behavior

Success

Actual Behavior

/Users/poupou/git/xamarin/SubmissionSamples/MacCoolApp_DontLink/MacCoolApp/MacCoolApp.csproj(89,11): error MSB4226: The imported project "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/Mac/Xamarin.Mac.CSharp.targets" was not found. Also, tried to find "Xamarin/Mac/Xamarin.Mac.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "/Library/Frameworks/Mono.framework/External/xbuild/" . These search paths are defined in "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/MSBuild.dll.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.

This does not seems to happen on d16-8 (or newer) and does not always happen.
I wonder if this only happens when downgrading ?!?

Environment

=== Visual Studio Enterprise 2019 for Mac ===

Version 8.7.4 (build 38)
Installation UUID: a8ba93d0-79b6-41af-a590-4edb9c2095b4
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000090

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.90 (2020-02/d3daacdaa80) (64-bit)
	Package version: 612000090

=== Xamarin Designer ===

Version: 16.7.0.492
Hash: f5afe667d
Branch: remotes/origin/d16-7-vsmac
Build date: 2020-07-10 18:42:54 UTC

=== Roslyn (Language Service) ===

3.7.0-6.20412.3+d3c3a44a4e7ad31cc75c59be0d3df4a19ff33878

=== NuGet ===

Version: 5.7.0.6702

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.100-rc.1.20426.3/Sdks
SDK Versions:
	5.0.100-rc.1.20426.3
	5.0.100-rc.1.20414.5
	5.0.100-preview.8.20359.11
	5.0.100-preview.7.20317.11
	5.0.100-preview.6.20265.2
	5.0.100-preview.5.20263.11
	5.0.100-preview.5.20256.10
	5.0.100-preview.5.20227.4
	5.0.100-preview.4.20214.36
	5.0.100-preview.1.20155.7
	3.1.200
	3.1.100
	2.1.806
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.0-rc.1.20425.16
	5.0.0-rc.1.20404.16
	5.0.0-rc.1.20371.13
	5.0.0-preview.8.20358.9
	5.0.0-preview.7.20317.2
	5.0.0-preview.6.20264.1
	3.1.2
	3.1.0
	2.1.21
	2.1.20
	2.1.18

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 11.0.2.0 (Visual Studio Enterprise)
Commit: xamarin-android/d16-7/025fde9
Android SDK: /Users/poupou/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.4 (API level 19)
		7.1 (API level 25)
		8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 29.0.5
SDK Build Tools Version: 29.0.2

Build Information: 
Mono: 83105ba
Java.Interop: xamarin/java.interop/d16-7@1f3388a
ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
SQLite: xamarin/sqlite/3.32.1@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/poupou/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.7.0.13
Hash: 8380518
Branch: remotes/origin/d16-7~2
Build date: 2020-08-19 22:18:28 UTC

=== Android Device Manager ===

Version: 16.7.0.24
Hash: bb090a3
Branch: remotes/origin/d16-7
Build date: 2020-08-19 22:18:52 UTC

=== Apple Developer Tools ===

Xcode 11.6 (16141)
Build 11E708

=== Xamarin.Mac ===

Version: 6.20.2.3 (Visual Studio Enterprise)
Hash: 64004ee25
Branch: d16-7
Build date: 2020-07-22 12:52:13-0400

=== Xamarin.iOS ===

Version: 13.20.2.3 (Visual Studio Enterprise)
Hash: 64004ee25
Branch: d16-7
Build date: 2020-07-22 12:52:13-0400

=== Build Information ===

Release ID: 807040038
Git revision: 7f322926a2e0a5fa0c1e3833215a191883f7514a
Build date: 2020-08-20 10:10:20-04
Build branch: release-8.7
Xamarin extensions: 7f322926a2e0a5fa0c1e3833215a191883f7514a

=== Operating System ===

Mac OS X 10.15.6
Darwin 19.6.0 Darwin Kernel Version 19.6.0
    Thu Jun 18 20:49:00 PDT 2020
    root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64

Build Logs

https://gist.github.com/spouliot/e8092ad8c26b9f322b3a97e68b736a34

Example Project (If Possible)

XM submissions tests can be used.

@spouliot spouliot added bug If an issue is a bug or a pull request a bug fix macOS Issues affecting macOS labels Aug 31, 2020
@spouliot spouliot added this to the d16-7 milestone Aug 31, 2020
@spouliot
Copy link
Contributor Author

There is no Xamarin directory under the /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/ directory

But it does not exists on the preview (or xcode12) channel either

@rolfbjarne
Copy link
Member

The Xamarin is in /Library/Frameworks/Mono.framework/External/xbuild/. The /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/ directory that shows up in the error could be a backup directory that's checked when the External one fails.

Could this be related to installing mono after Xamarin.Mac?

@spouliot
Copy link
Contributor Author

The Xamarin is in /Library/Frameworks/Mono.framework/External/xbuild/.

I'll double check it but it should be fine since XI has no issue...

Could this be related to installing mono after Xamarin.Mac?

No, that was my first thought too (and what I suggested to someone else who hit the issue before).

I re-installed XM (and XI) over the mono update and still got the same issue. I'll try nuking both to see if left-overs from upgrades/downgrades could explain it.

@spouliot
Copy link
Contributor Author

workaround: Nuking mono and XM and then re-installing both works.

rm -rf /Library/Frameworks/Mono.framework/
rm -rf /Library/Frameworks/Xamarin.Mac.framework/

So there's something after upgrades/downgrades that can break stable XM.

@projectgoav
Copy link

We have experienced but not everyone has been effected. We're all on latest XCode 11.6 and latest VSMac (within last week). Only 2 of the 4 of us get this issue.

It also effected our cloud builds provided by Bitrise (who may have been in touch directly regarding this issue)

@spouliot
Copy link
Contributor Author

spouliot commented Sep 3, 2020

I got this again after installed Xcode 12 preview (d16-7 based) on top of d16-8.
This does seems related to downgrading XM.

@spouliot
Copy link
Contributor Author

spouliot commented Sep 3, 2020

In this state

  • re-installing the current Xamarin.Mac does not help;
  • re-installing the current Mono does not help;
  • re-installing the current Mono and current Xamarin.Mac does not help;

but

  • nuking Mono and Xamarin.Mac then re-installing the current version works

@brminnick
Copy link

Thanks @spouliot!

Here's the steps I followed to fix it for me on macOS:

Uninstall Xamarin

Following the steps from the official Microsoft docs to uninstall Xamarin.iOS, Xamarin.Mac, Xamarin.Android and Visual Studio for Mac

  1. On macOS, save this script to as uninstall-vsmac.sh to ~/Downloads (ie ~/Downloads/uninstall-vsmac.sh
  2. On macOS, open the Terminal
  3. In the Terminal, enter the following commands:
cd ~/Downloads
chmod +x ./uninstall-vsmac.sh
sudo ./uninstall-vsmac.sh
  1. In the Terminal, if requested, enter your macOS password

Download/Install Visual Studio for Mac

  1. In a browser, navigate to https://visualstudio.microsoft.com/thank-you-downloading-visual-studio-mac/?sku=communitymac&rel=16
  2. Launch the Installer and follow the instructions on the installation wizard

@rolfbjarne
Copy link
Member

I think this happens because of 2420108, and problems occur when first installing a Xamarin.Mac version with those changes, then downgrading to one without.

It seems macOS isn't capable of properly installing a package that replaces a symlink with a directory, and instead ends up writing into where the symlink is pointing to. The broken result is that several files that should be files somehow end up as directories (note how all these *.targets and *.props files are in fact directories):

$ ls -la /Library/Frameworks/Xamarin.Mac.framework/Versions/6.20.2.2/lib/msbuild
total 56
drwxr-xr-x  20 rolf  wheel    640 Sep 14 14:36 .
drwxr-xr-x  31 rolf  wheel    992 Sep 14 14:36 ..
-rw-r--r--   1 rolf  wheel  25112 Jul 19 00:45 FrameworkList.xml
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Localization.MSBuild.dll
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.AppExtension.CSharp.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.AppExtension.Common.props
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.AppExtension.Common.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.CSharp.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.Common.ImplicitFacade.msbuild.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.Common.props
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.Common.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.FSharp.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.ObjCBinding.CSharp.props
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.ObjCBinding.CSharp.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.ObjCBinding.Common.props
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.ObjCBinding.Common.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.TargetFrameworkFix.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.Tasks.dll
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Mac.msbuild.targets
drwxr-xr-x   2 rolf  wheel     64 Sep 14 14:36 Xamarin.Shared.targets

The workaround is to manually remove /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac:

sudo rm -Rf /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac

and then reinstall the Xamarin.Mac pkg you want to install (there's no need to remove/reinstall Mono).

@praeclarum
Copy link
Contributor

praeclarum commented Sep 18, 2020

I'm running into this too with the Xcode 12 Preview.

Update: This seems fixed in the Stable channel today.

@tekmun
Copy link

tekmun commented Sep 30, 2020

Thanks @spouliot!

Here's the steps I followed to fix it for me on macOS:

Uninstall Xamarin

Following the steps from the official Microsoft docs to uninstall Xamarin.iOS, Xamarin.Mac, Xamarin.Android and Visual Studio for Mac

  1. On macOS, save this script to as uninstall-vsmac.sh to ~/Downloads (ie ~/Downloads/uninstall-vsmac.sh
  2. On macOS, open the Terminal
  3. In the Terminal, enter the following commands:
cd ~/Downloads
chmod +x ./uninstall-vsmac.sh
sudo ./uninstall-vsmac.sh
  1. In the Terminal, if requested, enter your macOS password

Download/Install Visual Studio for Mac

  1. In a browser, navigate to https://visualstudio.microsoft.com/thank-you-downloading-visual-studio-mac/?sku=communitymac&rel=16
  2. Launch the Installer and follow the instructions on the installation wizard

I followed this step but still getting the same error.
The installation did make a symlink /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/Mac -> /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/msbuild

The directory Xamarin.Mac.CSharp.targets is empty. Is this correct? Thanks.

@rolfbjarne
Copy link
Member

@tekmun Did you try this workaround?

The workaround is to manually remove /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac:

sudo rm -Rf /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Mac

and then reinstall the Xamarin.Mac pkg you want to install (there's no need to remove/reinstall Mono).

@amirvenus
Copy link

I tried the workaround, but I am still getting the same error.

@xtmq
Copy link

xtmq commented Nov 5, 2020

The same issue occurs when building SDK from sources.
I took the build e30c41d (tag xamarin-ios-14.4.1.3)
And after make world there is no Mono.framework folder inside _mac-build. Everything is OK with _ios-build meanwhile.

@xtmq
Copy link

xtmq commented Nov 22, 2020

Any updates on this? Thanks!

@rolfbjarne
Copy link
Member

@xtmq that particular xamarin-macios hash has the Xamarin.Mac build disabled, because the corresponding Xcode release doesn't ship with an updated macOS SDK.

This has recently changed (with Xcode 12.2), so you can use either the main or the d16-8 branch.

@KirillOsenkov
Copy link
Member

Ran into this too, and @ToddGrun has just run into this as well.

@shubhuuu
Copy link

I am facing the same issue till I have installed the fresh Visual Studio 2017 and the mac os 10.13.6.

/Users/shubhamagrawal/Projects/mloi/mloi.iOS/mloi.iOS.csproj(3,3): Error MSB4019: The imported project "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk. (MSB4019)

Please help me to resolve the issue.

@rolfbjarne
Copy link
Member

@shubhuuu that's a different issue, so please file a new issue so that this doesn't end up too confusing.

@decriptor
Copy link

I ran into this and used @rolfbjarne's workaround to unblock me

@justintoth
Copy link

For me, the solution was a bit different...

  1. Uninstall Visual Studio for Mac and Xamarin: https://docs.microsoft.com/en-us/visualstudio/mac/uninstall?view=vsmac-2019
  2. Download & install .NET Core SDK 3.1: https://dotnet.microsoft.com/download/dotnet/3.1
  3. Download Visual Studio for Mac: https://visualstudio.microsoft.com/vs/mac/preview/
  4. Install Visual Studio for Mac, but uncheck the .NET Core box

The last step is the crucial one, because by default Visual Studio for Mac (both 2019 & 2022 Preview) install the .NET 5 SDK, which isn't compatible with Xamarin. By following these steps, you will have .NET Core 3.1 installed but not .NET 5, which will allow Visual Studio for Mac > Xamarin projects to build successfully.

thsparks added a commit to xamarin/Xamarin.PropertyEditing that referenced this issue Mar 21, 2022
This is a workaround for xamarin/xamarin-macios#9550, which is causing build breaks in the CI validation pipeline...
thsparks added a commit to xamarin/Xamarin.PropertyEditing that referenced this issue Apr 25, 2022
This is a workaround for xamarin/xamarin-macios#9550, which is causing build breaks in the CI validation pipeline...
@rolfbjarne
Copy link
Member

Closing, this is not an issue anymore.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix macOS Issues affecting macOS
Projects
None yet
Development

No branches or pull requests