Dotnet new wpf linux

How to create a dotnet core WPF application using dotnet-cli

NET Core command-line interface (dotnet-cli) is a new NET Core toolset (commands) for developing NET Core Applications. The dotnet-cli toolset provides a list of pre-installed dotnet core project templates from which the user can create various applications as a dotnet core WPF (Windows Presentation Foundation) application, console application, Web application, Windows Form application, and other test applications. The application created with dotnet-cli can be executed on any Windows, Linux, or macOS operating system.

How to create a “dotnet core WPF application”

The user can use dotnet new “WPF Application” or “dotnet new wpf” command from the dotnet-CLI toolset to create a new dotnet core WPF (Windows Presentation Foundation) application. The command provides a few options that can be applied as a parameter to tweak the output of the command as shown below :

“dotnet new WPF –no-restore”: This command does not restore the required project dependencies by the WPF application. Please follow through to read about a few “dotnet new WPF” command usage.

Prerequisite:

.NET Core SDK 3.0 (preview) and above. The current version is .NET Core 5 and can be downloaded here:

Command Syntax

The format of the command is as follows: dotnet new wpf [options]

The details of the available command options can be listed using the –help option as follows:

c:\Temp\dotnet>dotnet new wpf --help Usage: new [options] Options: -h, --help Displays help for this command. -l, --list Lists templates containing the specified name. If no name is specified, lists all templates. -n, --name The name for the output being created. If no name is specified, the name of the current directory is used. -o, --output Location to place the generated output. -i, --install Installs a source or a template pack. -u, --uninstall Uninstalls a source or a template pack. --nuget-source Specifies a NuGet source to use during install. --type Filters templates based on available types. Predefined values are "project", "item" or "other". --dry-run Displays a summary of what would happen if the given command line were run if it would result in a template creation. --force Forces content to be generated even if it would change existing files. -lang, --language Filters templates based on language and specifies the language of the template to create. WPF Application (C#) Author: Microsoft Description: A project for creating a .NET Core WPF Application Options: --langVersion Sets langVersion in the created project file text - Optional --no-restore If specified, skips the automatic restore of the project on create. bool - Optional Default: false / (*) true * Indicates the value used if the switch is provided without a value.

Command Usage- dotnet new wpf:

1. “dotnet new wpf”

The command creates a new “NET Core WPF” project. The name of the project is not specified in the command so by default the project name will be the same as the directory where the command was executed, additionally, the command will also restore the dependency required by the project implicitly. The default language is C#, so the project created will be of C# type. The list of the file that will be created using the mentioned commands is given below.

c:\dotnet>dotnet new wpf The template "WPF Application" was created successfully. Processing post-creation actions. Running 'dotnet restore' on c:\dotnet\dotnet.csproj. Restore completed in 134.16 ms for c:\dotnet\dotnet.csproj. Restore succeeded.

The files generated by the command:

c:\dotnet>dir Volume in drive C is OSDisk Volume Serial Number is 8053-FAC8 Directory of c:\dotnet 06/14/2019 04:57 PM . 06/14/2019 04:57 PM .. 06/14/2019 04:57 PM 366 App.xaml 06/14/2019 04:57 PM 339 App.xaml.cs 06/14/2019 04:57 PM 224 dotnet.csproj 06/14/2019 04:57 PM 491 MainWindow.xaml 06/14/2019 04:57 PM 658 MainWindow.xaml.cs 06/14/2019 04:57 PM obj c:\dotnet\obj>dir Volume in drive C is OSDisk Volume Serial Number is 8053-FAC8 Directory of c:\dotnet\obj 06/14/2019 04:57 PM . 06/14/2019 04:57 PM .. 06/14/2019 04:57 PM 149 dotnet.csproj.nuget.cache 06/14/2019 04:57 PM 2,220 dotnet.csproj.nuget.dgspec.json 06/14/2019 04:57 PM 1,161 dotnet.csproj.nuget.g.props 06/14/2019 04:57 PM 294 dotnet.csproj.nuget.g.targets 06/14/2019 04:57 PM 2,300 project.assets.json

2. “dotnet new wpf –name Hello”

The command creates a new “NET Core WPF” project having the name of Hello.csproj. The command creates a Hello directory only if doesn’t exist and then creates the boilerplate files in the directory, additionally, the command also restores the dependency required by the project.

c:\>dotnet new wpf --name Hello The template "WPF Application" was created successfully. Processing post-creation actions. Running 'dotnet restore' on Hello\Hello.csproj. Restore completed in 98.33 ms for c:\Hello\Hello.csproj. Restore succeeded.

The files generated by the command:

c:\dotnet>dir Volume in drive C is OSDisk Volume Serial Number is 8053-FAC8 Directory of c:\dotnet 06/14/2019 04:57 PM . 06/14/2019 04:57 PM .. 06/14/2019 04:57 PM 366 App.xaml 06/14/2019 04:57 PM 339 App.xaml.cs 06/14/2019 04:57 PM 224 dotnet.csproj 06/14/2019 04:57 PM 491 MainWindow.xaml 06/14/2019 04:57 PM 658 MainWindow.xaml.cs 06/14/2019 04:57 PM obj c:\dotnet\obj>dir Volume in drive C is OSDisk Volume Serial Number is 8053-FAC8 Directory of c:\dotnet\obj 06/14/2019 04:57 PM . 06/14/2019 04:57 PM .. 06/14/2019 04:57 PM 149 dotnet.csproj.nuget.cache 06/14/2019 04:57 PM 2,220 dotnet.csproj.nuget.dgspec.json 06/14/2019 04:57 PM 1,161 dotnet.csproj.nuget.g.props 06/14/2019 04:57 PM 294 dotnet.csproj.nuget.g.targets 06/14/2019 04:57 PM 2,300 project.assets.json

3. “dotnet new wpf –name Hello –no-restore

The command creates a new “NET Core WPF” project having the name of Hello.csproj. The command creates a directory only if doesn’t exist and then creates the boilerplate files in the directory, the command does not restore the dependency required by the project. The output of the command is as follows:

c:\>dotnet new wpf --name Hello --no-restore The template "WPF Application" was created successfully. c:\Hello>dir Volume in drive C is OSDisk Volume Serial Number is 8053-FAC8 Directory of c:\Hello 06/14/2019 05:11 PM . 06/14/2019 05:11 PM .. 06/14/2019 05:11 PM 364 App.xaml 06/14/2019 05:11 PM 338 App.xaml.cs 06/14/2019 05:11 PM 224 Hello.csproj 06/14/2019 05:11 PM 489 MainWindow.xaml 06/14/2019 05:11 PM 657 MainWindow.xaml.cs

4. “dotnet new wpf –name Hello –langVersion 7.0”

The command creates a new “NET Core WPF” project having the name of Hello.csproj. The command creates a Hello directory only if doesn’t exist and then creates the boilerplate files and directory, additionally, the command also restores the dependency required by the project. The command creates the project specific to C# 7.0 (version). The details can be found in the Hello.csproj file.

C:\>dotnet new wpf --name Hello --langVersion 7.0 The template "WPF Application" was created successfully. Processing post-creation actions. Running 'dotnet restore' on Hello\Hello.csproj. Restore completed in 123.41 ms for C:\Hello\Hello.csproj. Restore succeeded.

Content of Hello.csproj file: LangVersion tag contains 7.0

C:\Hello>type Hello.csproj  WinExe netcoreapp3.0 7.0 true  

I hope you found this post on how to create a dotnet core WPF application using dotnet-cli helpful. Thanks for visiting. Cheers .

Читайте также:  Как посмотреть сетевую карту линукс

Источник

Running/Migrating a WPF application into Linux

We have developed a WPF application that is widely used by users who have the Windows operating system on their machines. Now, we would like to also reach users who use Linux.

What would be the best approach for such a migration?

I did a little research and found these following options:

Option 1: .NET Core 3.0’s support for WPF, a WPF application can run on Linux under Wine. Wine is a compatibility layer which allows Windows applications on Linux and other OSes, including .NET Core Windows applications.
I’ve discovered this possibility by reading the following article:
https://ccifra.github.io/PortingWPFAppsToLinux/Overview.html

When I showed this solution to my team members, they claimed that according to their past experience, Wine has some major performance pitfalls. Should I test it out or it’s indeed not recommended for such a migration, according to your experience?

Option 2: I’ve also read about .NET MAUI, via this article on Microsoft blogs:
https://devblogs.microsoft.com/dotnet/introducing-net-multi-platform-app-ui/

I’m really not sure if .NET MAUI supports Linux, as the article only mentioned the Android, iOS, macOS, and Windows operating systems.
Is it possible to use it for migrating a WPF app into Linux?

If the options I’ve suggested are not great, what other options I might have for doing such a migration?

Thank you for your help and I’m looking forward to your reply,
Dima

A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.

Источник

Оцените статью
Adblock
detector