laitimes

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

author:opendotnet

1. Introduction

Develop in network-constrained or completely offline environments. The .NET project (in this case, the Avalonia UI project) can be challenging. This article will provide you with a complete set of offline development solutions, including IDE installation, configuration of Avalonia UI templates, deployment of privatized NuGet services, and production and upload of NuGet packages.

2. IDE Installation Guide

Visual Studio 2022 Installation

Visual Studio 2022 is the latest IDE launched by Microsoft to support the development of the Avalonia UI project. Here are the detailed offline installation steps:

  • Offline installation package production: First, according to the guide of VS2022 offline installation package [1], make an offline installation package for Visual Studio 2022.
  • Avalonia UI扩展安装:安装Visual Studio后,通过 Visual Studio Marketplace[2] 下载并安装Avalonia for Visual Studio 2022扩展。
AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment
  • A failure was encountered during the installation process
AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

According to the answer of the @rabbitism in the WeChat group (thanks to the @daidai_cn for your help), we can delete the box selected in the following figure by unzipping the extension file

Extension.vsext

file before installing:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

Installed normally:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

JetBrains Rider安装

The JetBrains Rider[3] IDE has built-in support for Avalonia XAML in the 2020.3 release, including best-in-class support for Avalonia-specific XAML features and custom code checks.

3. Install the Avalonia UI template

在线安装请参考文档 Avalonia Docs[5],离线安装请点击 Avalonia.Templates[6] 下载:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

The installation method is the same as above

.NET CLI

Command Script:

dotnet new install avalonia.templates.11.0.10.1.nupkg
           
AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

Now, whether in Visual Studio or JetBrains Rider, you can use Avalonia UI templates to create new projects.

VS 2022 The Ui

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

Templates to use in Rider:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

4. Deploy NuGet services privately

After creating the project, the program will not run normally, the default template depends on some NuGet packages of Avalonia UI, which needs to be installed online, and the relevant libraries can be copied directly to the intranet, but it is still very troublesome to copy and reference one by one.

To make it easier to share and manage NuGet packages among members of your team, you may want to consider deploying a private NuGet service. In this article, we recommend using BaGet as a lightweight NuGet server, refer to the description of the BaGet project [7]:

  1. Install the .NET Core 3.1 [8] SDK, which supports . .NET latest version, interested can be modified into Clone

    .NET 8\9

    (There are surprises in PR, and netizens have PR upgrade branches);
  2. 下载最新版的Release压缩包 Releases · loic-sharma/BaGet [9]
  3. Run the service

    dotnet BaGet.dll

  4. The browser opens

    http://localhost:5000

    Visit:
AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

OK, that's done.

5. NuGet Package Making (Omitted)

There are many online tutorials, and the engineering files of the library can be easily configured to support NuGet package generation, refer to CodeWF.EventBus [10]:

<Project>
<PropertyGroup>
<Company>https://codewf.com</Company>
<Authors>沙漠尽头的狼</Authors>
<Owners>https://codewf.com</Owners>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Version>$(Version)</Version>
<Description>通过 CodeWF.EventBus 提供的 事件总线,我们可以很轻松的实现 CQRS 模式。根据业务需求,我们可以创建并维护读模型,将读操作和写操作进行分离,从而提高应用程序的可扩展性和性能。可在各种模板项目使用:WPF、Winform、AvaloniaUI、ASP.NET Core等。The CodeWF.EventBus allows us to easily implement the CQRS mode. According to business requirements, we can create and maintain a read model to separate read and write operations, thereby improving the scalability and performance of the application. Can be used in various template projects: WPF, Winform, AvaloniaUI, ASP. NET Core, etc.</Description>
<ApplicationIcon>Resources\logo.ico</ApplicationIcon>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>$(AssemblyName)</Title>
<Copyright>Copyright © https://codewf.com 2024</Copyright>
<AssemblyName>$(AssemblyName)</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace>
<PackageId>$(AssemblyName)</PackageId>
<PackageTags>C# EventBus; WPF; Winform; AvaloniaUI,ASP.NET Core;</PackageTags>
<PackageIcon>logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/dotnet9/CodeWF.EventBus</PackageProjectUrl>
<RepositoryUrl>https://github.com/dotnet9/CodeWF.EventBus</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<None Include="Resources\logo.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
</Project>
           

When the library project is generated, the corresponding NuGet file will be generated, and here is the address of the published NuGet package: https://www.nuget.org/packages/CodeWF.EventBus

6. NuGet package upload

You can upload your own NuGet package, or you can upload a NuGet package from the NuGet website[11] or a third party.

Let's open the NuGet homepage of our deployment

http://localhost:5000

:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

click

Upload a package

to switch to the NuGet package upload command:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

We take it as:

.NET CLI

To upload a NuGet package, first prepare a NuGet file, for example, search for [12] from the NuGet official website to download the basic package of Avalonia UI:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment
AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

After downloading, open the CMD command line in the current download directory and type:

dotnet nuget push -s http://localhost:5000/v3/index.json avalonia.11.1.0-rc1.nupkg
           
AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

The above prompts that the NuGet service is configured with a key, so let's stop the NuGet service first and open its configuration file for the sake of simplicity

appsettings.json

empty

ApiKey

node value, and then run the NuGet service:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

Execute the upload command again, and now it is successful:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

The NuGet homepage can also be searched:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

7. Configure the NuGet source in the IDE

Copy the URL address in red font in the image of the previous NuGet upload page:

http://localhost:5000/v3/index.json

, configure NuGet to search for addresses in VS:

AvaloniaUI project offline development strategy: one-stop solution for IDE installation, template application, and NuGet private deployment

The rest is the same as the usual installation package.

8. Summary

This article describes how to successfully install and configure the development tools and templates required for AvaloniaUI in your local network environment, as well as how to deploy a private NuGet service and make and upload NuGet packages for sharing and managing among team members.

Hopefully, this information will be helpful in the development of your AvaloniaUI project. If you have any other questions, please feel free to ask me.

References[1]

VS2022 Offline Installation Package: https://www.cnblogs.com/sailJs/p/16864697.html

[2]

Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaVS

[3]

JetBrains Rider: https://www.jetbrains.com/rider/

[4]

下载 Rider:跨平台 .NET IDE (jetbrains.com): https://www.jetbrains.com/zh-cn/rider/download/#section=windows

[5]

Avalonia Docs: https://docs.avaloniaui.net/zh-Hans/docs/get-started/install

[6]

Avalonia.Templates: https://www.nuget.org/packages/Avalonia.Templates

[7]

BaGet Project Description: https://github.com/loic-sharma/BaGet

[8]

.NET Core 3.1 : https://dotnet.microsoft.com/zh-cn/download/dotnet/3.1

[9]

Releases · loic-sharma/BaGet : https://github.com/loic-sharma/BaGet/releases

[10]

CodeWF.EventBus: https://github.com/dotnet9/CodeWF.EventBus

[11]

NuGet Official Website: https://www.nuget.org/

[12]

NuGet Official Website Search: https://www.nuget.org/packages?q=avalonia

Read on