unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
9.04k stars 734 forks source link

Build new project from template fails on Linux #11753

Closed darkoverlordofdata closed 1 year ago

darkoverlordofdata commented 1 year ago

Current behavior

I'm following the instructions at https://platform.uno/docs/articles/get-started-vscode.html?tabs=linux to create a new project, I entered:

dotnet new unoapp -o MyAppz -mobile=false --skia-wpf=false --skia-linux-fb=false 

I get an error:

The template "Multi-Platform App (Windows App SDK)" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/darko/Documents/GitHub/MyAppz/MyAppz.Server/MyAppz.Server.csproj...
  Determining projects to restore...
/usr/lib/dotnet/sdk/6.0.113/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0.  Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0. [/home/darko/Documents/GitHub/MyAppz/MyAppz.Wasm/MyAppz.Wasm.csproj]
/usr/lib/dotnet/sdk/6.0.113/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0.  Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0. [/home/darko/Documents/GitHub/MyAppz/MyAppz.Server/MyAppz.Server.csproj]
Restore failed.
Running 'dotnet restore' on /home/darko/Documents/GitHub/MyAppz/MyAppz.Windows/MyAppz.Windows.csproj...
  Determining projects to restore...
/usr/lib/dotnet/sdk/6.0.113/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0.  Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0. [/home/darko/Documents/GitHub/MyAppz/MyAppz.Windows/MyAppz.Windows.csproj]
Restore failed.
Running 'dotnet restore' on /home/darko/Documents/GitHub/MyAppz/MyAppz.Skia.Gtk/MyAppz.Skia.Gtk.csproj...
  Determining projects to restore...
/usr/lib/dotnet/sdk/6.0.113/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 7.0.  Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0. [/home/darko/Documents/GitHub/MyAppz/MyAppz.Skia.Gtk/MyAppz.Skia.Gtk.csproj]
Restore failed.
Post action failed.
Manual instructions: Run 'dotnet restore'

So, I added --framework net6.0, and it created correctly. Now I try yo build it:

dotnet build "/home/darko/Documents/GitHub/MyApp/MyApp.Skia.Gtk/MyApp.Skia.Gtk.csproj"

and I get a new error:

Feature 'not pattern' is not available in C# 7.3. Please use language version 9.0 or greater. [MyApp]csharp(CS8370)

    <TargetFramework>net6.0</TargetFramework>

darko@barsoomian:~/Documents/GitHub/MyApp$ dotnet build "/home/darko/Documents/GitHub/MyApp/MyApp.Skia.Gtk/MyApp.Skia.Gtk.csproj"
Microsoft (R) Build Engine version 17.0.1+b177f8fa7 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
/home/darko/Documents/GitHub/MyApp/MyApp/App.cs(9,1): error CS8370: Feature 'file-scoped namespace' is not available in C# 7.3. Please use language version 10.0 or greater. [/home/darko/Documents/GitHub/MyApp/MyApp/MyApp.csproj]
/home/darko/Documents/GitHub/MyApp/MyApp/App.cs(56,29): error CS8370: Feature 'not pattern' is not available in C# 7.3. Please use language version 9.0 or greater. [/home/darko/Documents/GitHub/MyApp/MyApp/MyApp.csproj]

Build FAILED.

/home/darko/Documents/GitHub/MyApp/MyApp/App.cs(9,1): error CS8370: Feature 'file-scoped namespace' is not available in C# 7.3. Please use language version 10.0 or greater. [/home/darko/Documents/GitHub/MyApp/MyApp/MyApp.csproj]
/home/darko/Documents/GitHub/MyApp/MyApp/App.cs(56,29): error CS8370: Feature 'not pattern' is not available in C# 7.3. Please use language version 9.0 or greater. [/home/darko/Documents/GitHub/MyApp/MyApp/MyApp.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:06.65

Expected behavior

I'm expecting this to compile correctly.

How to reproduce it (as minimally and precisely as possible)

dotnet new unoapp -o MyAppz -mobile=false --skia-wpf=false --skia-linux-fb=false --vscode --framework net6.0 dotnet build "/home/darko/Documents/GitHub/MyApp/MyApp.Skia.Gtk/MyApp.Skia.Gtk.csproj"

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

dotnet list package Project 'MyApp' has the following package references [netstandard2.0]: Top-level Package Requested Resolved

Microsoft.Extensions.Logging.Console 5.0.0 5.0.0
NETStandard.Library (A) [2.0.3, ) 2.0.3
Uno.Core.Extensions.Logging.Singleton 4.0.1 4.0.1
Uno.WinUI 4.7.44 4.7.44

Project 'MyApp.Wasm' has the following package references [net6.0]: Top-level Package Requested Resolved

Microsoft.Extensions.Logging 6.0.0 6.0.0
Microsoft.Windows.Compatibility 6.0.0 6.0.0
Uno.Extensions.Logging.WebAssembly.Console 1.4.0 1.4.0
Uno.UI.Adapter.Microsoft.Extensions.Logging 4.7.44 4.7.44
Uno.Wasm.Bootstrap 7.0.11 7.0.11
Uno.Wasm.Bootstrap.DevServer 7.0.11 7.0.11
Uno.WinUI.Lottie 4.7.44 4.7.44
Uno.WinUI.RemoteControl 4.7.44 4.7.44
Uno.WinUI.WebAssembly 4.7.44 4.7.44

Project 'MyApp.Server' has the following package references [net6.0]: Top-level Package Requested Resolved

Uno.Wasm.Bootstrap.Server 7.0.0-dev.195 7.0.0-dev.195

Project 'MyApp.Skia.Gtk' has the following package references [net6.0]: Top-level Package Requested Resolved

Microsoft.Extensions.Logging.Console 5.0.0 5.0.0
SkiaSharp.Skottie 2.88.3 2.88.3
SkiaSharp.Views.Uno.WinUI 2.88.3 2.88.3
Uno.UI.Adapter.Microsoft.Extensions.Logging 4.7.44 4.7.44
Uno.WinUI.Lottie 4.7.44 4.7.44
Uno.WinUI.RemoteControl 4.7.44 4.7.44
Uno.WinUI.Skia.Gtk 4.7.44 4.7.44

No assets file was found for /home/darko/Documents/GitHub/MyApp/MyApp.Windows/MyApp.Windows.csproj. Please run restore before running this command.

(A) : Auto-referenced package.

Affected platforms

Skia (GTK on Linux/macOS/Windows)

IDE

No response

IDE version

Not using IDE

Relevant plugins

No response

Anything else we need to know?

I'm using Ubuntu 22.04 lts, dotnet --version 6.0.113.

dotnet --list-sdks 2.1.202 [/usr/lib/dotnet/sdk] 5.0.408 [/usr/lib/dotnet/sdk] 6.0.113 [/usr/lib/dotnet/sdk] 7.0.200 [/usr/lib/dotnet/sdk]

dotnet --list-runtimes Microsoft.AspNetCore.App 5.0.17 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.13 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.3 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.9 [/usr/lib/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [/usr/lib/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.13 [/usr/lib/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.3 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]

Currently, I'm able to compile other projects, no problem.

Youssef1313 commented 1 year ago

Can you try installing .NET 7 SDK?

jeromelaban commented 1 year ago

@darkoverlordofdata it seems that you're running a versions of the templates that provide a global.json file which reverts to .NET 6. You can try to either:

darkoverlordofdata commented 1 year ago

Adding a global.json had no effect. But it was the template.

In MyApp/MyApp.csproj line 4 I changed

$(TargetFrameworks);netstandard2.0

to

$(TargetFrameworks);net6.0;netstandard2.0

and now it works. I can only verify this on Linux.

(don't reply from email. i cleaned up)

jeromelaban commented 1 year ago

Thanks. The log you provided were using the net6.0 SDK, while the app was requesting net7.0. Given that the .NET 7.0 SDK is installed and accessible, the only for this to happen is to have a global.json somewhere in your tree.

If you remove the global.json that you just added, If you run dotnet --version in your app's folder, what does it show?

darkoverlordofdata commented 1 year ago

I see what happens. Dotnet version 6 is the default version on Ubuntu, so I normally use 6.

When I typed in

dotnet new unoapp -o MyApp -mobile=false --skia-wpf=false --skia-linux-fb=false --vscode

I got a message:

The template "Multi-Platform App (Windows App SDK)" was created successfully.

The current .NET SDK does not support targeting .NET 7.0.  Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 7.0. 

My response was the 1st choice, target .NET 6.0 by typing

dotnet new unoapp -o MyApp -mobile=false --skia-wpf=false --skia-linux-fb=false --vscode --framework net6.0

So, I have to follow the 2nd choice, choice 1 doesn’t work. I’ve set my default version to 7.0, and started over, and everything then works.

darkoverlordofdata commented 1 year ago

on your documentation, at https://platform.uno/docs/articles/get-started-dotnet-new.html?tabs=net7%2Cwindows, there are instructions for creating a new template with either donet6 or dotnet7, It says:

NOTE When using .NET 6, use dotnet new -i Uno.Templates instead.

Either the documentation is out of date, or the template is broken.

When I 'tricked' it into using dotnet 6, the resulting application works. If that should be a valid option, as it shows in your documentation, then your template is broken and it should pick whichever is requested.

dotnet new templates for Uno Platform
jeromelaban commented 1 year ago

Thanks for the feedback.

That's unfortunately a limitation of the dotnet new templating engine with regards to which target is being used by default. We'll adjust the documentation, still, as you can use -f net6.0 to create a net6.0 only solution.

*edit: Actually, the documentation already mentions the -f net6.0 option: https://github.com/unoplatform/uno/blob/d61288f4a6f3ea128a0b3a5470110266b8466b41/doc/articles/get-started-dotnet-new.md?plain=1#L51