dotnet / upgrade-assistant

A tool to assist developers in upgrading .NET Framework applications to .NET 6 and beyond
MIT License
1.1k stars 163 forks source link

Xamarin Android and Xamarin iOS CLI tool cannot find .CSharp.targets file #1496

Closed GalaxiaGuy closed 1 year ago

GalaxiaGuy commented 1 year ago

I could not find a file upgrade-assistant.clef.

Describe the bug

When trying to run the CLI tool on any iOS or Android project, I get an error that the .CSharp.targets file cannot be found.

Exceptions (if any)

Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/usr/local/share/dotnet/sdk/7.0.202/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.202/Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.

Full stack trace: ``` Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/usr/local/share/dotnet/sdk/7.0.202/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/7.0.202/Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk. /Users/obbbrown/Documents/Repos/MobileAppsGit/Apps/TotalPlatformCommon.iOS/TotalPlatformCommon.iOS.csproj at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpression(String directoryOfImportingFile, ProjectImportElement importElement, String unescapedExpression, Boolean throwOnFileNotExistsError, List`1& imports) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator`4.Evaluate() at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive) at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion) at Microsoft.UpgradeAssistant.Services.DefaultMsbuildProjectAccess..ctor(String projectPath, ILogger logger, CancellationToken cancellationToken) at Microsoft.UpgradeAssistant.Cli.Slices.Services.Msbuild.MsbuildService.GetProjectAccessAsync(String projectPath, Boolean isReadOnly, ILogger logger, CancellationToken cancellationToken) at Microsoft.UpgradeAssistant.Cli.Slices.Services.Project.MsbuildProjectBuilder.BuildAsync(ISolution solution, String projectPath, CancellationToken cancellationToken) at Microsoft.UpgradeAssistant.Cli.Slices.Services.Project.ProjectService.GetProjectAsync(ISolution solution, String projectPath, CancellationToken cancellationToken) at Microsoft.UpgradeAssistant.Cli.Slices.Services.Project.ProjectService.GetProjectByPathAsync(ISolution solution, String projectPath, ILogger logger, CancellationToken cancellationToken) at UpgradeHost.GetTraitsAsync(String projectPath, CancellationToken cancellationToken) at Spectre.Console.Flow.FlowContextExtensions.GetOriginalTraitsAsync(IFlowContext context, String projectPath, IUpgradeHost host, CancellationToken cancellationToken) at Microsoft.UpgradeAssistant.Cli.Flow.Steps.Upgrade.SelectControllerFlowStep.<>c__DisplayClass8_0.<b__0>d.MoveNext() --- End of stack trace from previous location --- at Spectre.Console.Status.<>c__DisplayClass17_0`1.<b__0>d.MoveNext() in /_/src/Spectre.Console/Live/Status/Status.cs:line 120 --- End of stack trace from previous location --- at Spectre.Console.Progress.<>c__DisplayClass28_0`1.<b__0>d.MoveNext() in /_/src/Spectre.Console/Live/Progress/Progress.cs:line 133 --- End of stack trace from previous location --- at Spectre.Console.Internal.DefaultExclusivityMode.RunAsync[T](Func`1 func) in /_/src/Spectre.Console/Internal/DefaultExclusivityMode.cs:line 40 at Spectre.Console.Progress.StartAsync[T](Func`2 action) in /_/src/Spectre.Console/Live/Progress/Progress.cs:line 116 at Spectre.Console.Status.StartAsync[T](String status, Func`2 func) in /_/src/Spectre.Console/Live/Status/Status.cs:line 117 at Microsoft.UpgradeAssistant.Cli.Flow.Steps.Upgrade.SelectControllerFlowStep.ValidateUserInputAsync(IFlowContext context, CancellationToken cancellationToken) at Spectre.Console.Flow.FlowRunner.RunAsync(CancellationToken cancellationToken) ```

Further technical details

2.1.816 [/usr/local/share/dotnet/sdk]
3.1.409 [/usr/local/share/dotnet/sdk]
3.1.410 [/usr/local/share/dotnet/sdk]
3.1.412 [/usr/local/share/dotnet/sdk]
3.1.413 [/usr/local/share/dotnet/sdk]
3.1.414 [/usr/local/share/dotnet/sdk]
3.1.415 [/usr/local/share/dotnet/sdk]
3.1.417 [/usr/local/share/dotnet/sdk]
3.1.420 [/usr/local/share/dotnet/sdk]
3.1.423 [/usr/local/share/dotnet/sdk]
3.1.424 [/usr/local/share/dotnet/sdk]
3.1.425 [/usr/local/share/dotnet/sdk]
3.1.426 [/usr/local/share/dotnet/sdk]
5.0.203 [/usr/local/share/dotnet/sdk]
5.0.301 [/usr/local/share/dotnet/sdk]
5.0.400 [/usr/local/share/dotnet/sdk]
5.0.401 [/usr/local/share/dotnet/sdk]
5.0.402 [/usr/local/share/dotnet/sdk]
5.0.403 [/usr/local/share/dotnet/sdk]
5.0.406 [/usr/local/share/dotnet/sdk]
5.0.408 [/usr/local/share/dotnet/sdk]
6.0.401 [/usr/local/share/dotnet/sdk]
6.0.402 [/usr/local/share/dotnet/sdk]
6.0.403 [/usr/local/share/dotnet/sdk]
6.0.404 [/usr/local/share/dotnet/sdk]
6.0.405 [/usr/local/share/dotnet/sdk]
6.0.406 [/usr/local/share/dotnet/sdk]
6.0.407 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]
7.0.200 [/usr/local/share/dotnet/sdk]
7.0.202 [/usr/local/share/dotnet/sdk]

jstedfast commented 1 year ago

Does the path /Library/Frameworks/Mono.framework/External/xbuild exist on your system? Does it contain a Xamarin directory?

IanBUK commented 1 year ago

It does indeed.

I'll try hard-coding that in a moment or two...I'm just seeing if I can 'easily' knock together a Maui version of BLE.Client.Droid.

IanBUK commented 1 year ago

I end up back with the following error:

/usr/local/share/dotnet/sdk/7.0.305/Microsoft.Common.CurrentVersion.targets(5,5): Error: Project '../../MvvmCross.Plugins.BLE/MvvmCross.Plugins.BLE.csproj' targets 'net6.0-android;net6.0-ios;net6.0-maccatalyst;net7.0-android;net7.0-ios;net7.0-maccatalyst'. It cannot be referenced by a project that targets 'MonoAndroid,Version=v12.0'. (BLE.Client.Droid)

IanBUK commented 1 year ago

My 'Add base Maui App' is at: https://github.com/IanBUK/dotnet-bluetooth-le

jstedfast commented 1 year ago

I actually was able to reproduce this yesterday and started working on a fix.

As a temporary work-around, you can probably add symlinks in /usr/share/dotnet/sdk/7.0.xxx (or whatever version that the upgrade-assistant ends up deciding to use) that point to /Library/Frameworks/Mono.framework/Extensions/xbuild/Novell and /Library/Frameworks/Mono.framework/Extensions/xbuild/Xamarin

That should hopefully get you further along, but you may run into other macOS port bugs. Let me know how that works out for you.

IanBUK commented 1 year ago

I’ve got some family and work stuff for the next few days, so I might not be able to try until Saturday, but I’ll see if I can squeeze some them in. Thanks On 8 Jul 2023, at 19:44, Jeffrey Stedfast @.***> wrote: I actually was able to reproduce this yesterday and started working on a fix. As a temporary work-around, you can probably add symlinks in /usr/share/dotnet/sdk/7.0.xxx (or whatever version that the upgrade-assistant ends up deciding to use) that point to /Library/Frameworks/Mono.framework/Extensions/xbuild/Novell and /Library/Frameworks/Mono.framework/Extensions/xbuild/Xamarin That should hopefully get you further along, but you may run into other macOS port bugs. Let me know how that works out for you.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

jtorvald commented 1 year ago

The symlink helped my upgrade-assistent to run, but the resulting project was not usable. I also ran into some other issue when running upgrade assistant: #1500

cd /usr/local/share/dotnet/sdk/7.0.305/    
sudo ln -s /Library/Frameworks/Mono.framework/External/xbuild/Xamarin  .
jstedfast commented 1 year ago

Looks like the new upgrade assistant code-base (which is not located in this repo) is going to take a while to port to macOS. It's not going to be as trivial as I had hoped (i.e. just fixing things to be able to locate the Xamarin.iOS/Android/etc targets files).

I would recommend trying to use the tool from Windows for the time being until I can figure out how to port the new code-base to macOS.

jtorvald commented 1 year ago

@jstedfast Thanks, good to know that they are not the same. I will give it a try on Windows.

IanBUK commented 1 year ago

It looks like at least some of the problems are caused by the mvvm framework being used.

I’m going to try, on Saturday, putting together a simple Maui app without the mvvm framework, using some simpler binding - in an attempt to rule this out.

IanBUK commented 1 year ago

So, I've got a new commit in https://github.com/IanBUK/dotnet-bluetooth-le.git

This adds a simple Maui app to the solution. I've got to the point where an app framework is in place and you can press the "Scan" button. It then fails with a permissions test on Android, which hopefully shouldn't take too long to fix.

However, it's referencing BLE.Plugin quite happily, compiling and running.

So, that's a start.

EeKay commented 1 year ago

Looks like the new upgrade assistant code-base (which is not located in this repo) is going to take a while to port to macOS. It's not going to be as trivial as I had hoped (i.e. just fixing things to be able to locate the Xamarin.iOS/Android/etc targets files).

I would recommend trying to use the tool from Windows for the time being until I can figure out how to port the new code-base to macOS.

Hey there, and thanks for all the work on the upgrade assistant. I managed to make it go when adding the symlink to the Xamarin directory.

Unfortunately, I couldn't run it using --no-interaction as it stated "Invalid project path". After running it with interactions, I first migrated the Android, then the IOS project (in-place).

Now working on "Invalid restore input. Duplicate frameworks found: 'xamarinios10, xamarinios10' issue.

jstedfast commented 1 year ago

@EeKay,

Weird, you got further than I've gotten. The symlink hack that I had suggested in an earlier comment got the build to be able to find the Xamarin.[Android,iOS].CSharp.targets files, but then it couldn't locate the Xamarin.iOS v1.0 or MonoANdroid v11.0 frameworks, so I had to modify my *.csproj files by adding <TargetFrameworkRootPath>/Library/Frameworks/Mono.framwework/External/xbuild-frameworks</TargetFrameworkRootPath>. Once I did that, I was able to build.

I've got a local patch that fixes the upgrade-assistant to create the proper symlinks for users (I did this in the 0.4.x version of the upgrade-assistant but when the logic got copied over to the 0.5 version, something broke and needed some tweaking), but I've been struggling to get the TargetFrameworkRootPath hack to work when loading projects in the upgrade-assistant.

So that's where I'm at right now...

EeKay commented 1 year ago

@jstedfast perhaps it had something to do with my project setup? Although the core wasn't that weird: Xamarin.Forms project with a shared project, and both an iOS and Android target.. some nugets that all got upgraded properly.

Working on two things now:

Issue 1. double frameworks I've been looking into the xamarinios10, xamarinios10 issue. The literal compile error was:

Invalid restore input. Duplicate frameworks found: 'xamarinios10, xamarinios10'. Input files: /mydirs/Projectname/Projectname.iOS/Projectname iOS.csproj.

I was checking the .csproj files, and all I can find is that BOTH the iOS and Android csproj state the following targetframeworks:

<TargetFrameworks>net7.0-android;net7.0-ios</TargetFrameworks>

I reckon that I need to change this to "net7.0-android; for the Android, and the ios variant for the ios project (this might have happened because I "upgraded the android and then ios project separately" using the interactive mode?

Issue 2. cannot set ios starter project Perhaps because I upgraded both projects in the interactive mode one after eachother, but I cannot select the Myproject.iOS project as startup project. I CAN do this for the Android version.

Same with selecting the "debug" or "debug|iphone" target; it doesn't select/activate the proper platform project anymore like it did with Xamarin.Forms...

jstedfast commented 1 year ago

I've got this working now for macOS. Should be released in another 2 weeks or so when the next release happens.