Comprehensive strategy for offline development of AvaloniaUI project: One-stop solution for IDE installation, template application and NuGet privatization deployment

Comprehensive strategy for offline development of AvaloniaUI project: One-stop solution for IDE installation, template application and NuGet privatization deployment

This article will guide you on how to successfully install and configure the tools and templates required for Avalonia UI in a local network environment.

最后更新 6/28/2024 10:26 PM
沙漠尽头的狼
预计阅读 6 分钟
分类
Avalonia UI
标签
.NET C# Avalonia UI NuGet

1. introduction

Developing a. NET project in a network-limited or completely offline environment (the example in this article is the Avalonia UI project) may encounter some challenges. This article will provide you with a complete offline development solution, including IDE installation, Avalonia UI template configuration, privatized NuGet service deployment, and NuGet package creation and upload.

2. IDE Installation Guide

Visual Studio 2022 installation

Visual Studio 2022 is the latest IDE launched by Microsoft that supports the development of Avalonia UI projects. Here are the detailed offline installation steps:

  • 离线安装包制作:首先,根据网友 VS2022离线安装包 的指南,制作Visual Studio 2022的离线安装包。
  • Avalonia UI扩展安装:安装Visual Studio后,通过 Visual Studio Marketplace 下载并安装Avalonia for Visual Studio 2022扩展。

  • Failure encountered during installation

根据微信群内@rabbitism的解答(感谢@daidai_cn的帮助),我们可以通过解压该扩展文件,删除下图框选的Extension.vsext文件后再进行安装:

Installed normally:

JetBrains Rider installation

JetBrains Rider IDE在2020.3版本中开始内置支持Avalonia XAML,包括对Avalonia特定XAML功能和自定义代码检查的一流支持。

离线安装包下载地址:下载 Rider:跨平台 .NET IDE (jetbrains.com)

3. Install the Avalonia UI template

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

安装方式同上图.NET CLI命令脚本:

dotnet new install avalonia.templates.11.0.10.1.nupkg

You can now use the Avalonia UI template to create new projects, whether in Visual Studio or JetBrains Rider.

Avalonia UI templates in VS 2022:

Templates used in Rider:

4. Privatize and deploy NuGet services

After creating the project, the program cannot run normally. The default template relies on some NuGet packages in the Avalonia UI and requires online installation. You can directly copy relevant libraries to the intranet, but copying and referencing one by one is still very troublesome.

为了方便团队内部成员之间共享和管理NuGet包,您可以考虑部署私有NuGet服务。本文推荐使用BaGet作为轻量级的NuGet服务器,参考该BaGet项目说明

  1. 安装 .NET Core 3.1 SDK,该程序能支持的.NET最新版本,有兴趣可以Clone修改成.NET 8\9(PR中有惊喜,网友有PR升级分支);
  2. 下载最新版的Release压缩包 Releases · loic-sharma/BaGet
  3. 运行服务dotnet BaGet.dll
  4. 浏览器打开http://localhost:5000访问:

OK, this is the deployment completed.

5. NuGet bag making (can be omitted)

网上教程较多,可简单配置库的工程文件支持NuGet包生成,参考CodeWF.EventBus

<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 generating the library project, the corresponding NuGet file will be generated. Here is the address of the released NuGet package: www.nuget.org/packages/CodeWF.EventBus

6. NuGet package upload

可以上传自己制作的NuGet包,也可以上传从 NuGet官网 或第三方获得的NuGet包。

我们打开自己部署的NuGet首页http://localhost:5000:

点击Upload a package,切换到NuGet包上传命令说明:

我们以.NET CLI上传NuGet包举例,首先准备NuGet文件,比如从NuGet官网搜索下载Avalonia UI的基础包:

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

dotnet nuget push -s http://localhost:5000/v3/index.json avalonia.11.1.0-rc1.nupkg

上面提示NuGet服务配置了密钥,我们为了简单,先停止NuGet服务,打开它的配置文件appsettings.json,清空ApiKey节点值,再运行NuGet服务:

Then execute the upload command, and now it succeeds:

You can also search on the NuGet homepage:

7. IDE Configure NuGet Sources

复制前面NuGet上传页面图中红色字体的URL地址:http://localhost:5000/v3/index.json, 在VS中配置NuGet搜索地址:

The rest is consistent with the usual installation package.

小知识:个人临时开发可将上面的源配置为本地NuGet目录路径。

8. summary

This article describes how to successfully install and configure the development tools and templates required for AvaloniaUI in a local network environment, as well as how to deploy a private NuGet service and make and upload NuGet packages so that NuGet packages can be shared and managed among team members.

I hope this information will be helpful to your AvaloniaUI project development. If you have any other questions, please feel free to ask me questions.

Keep Exploring

延伸阅读

更多文章
同分类 / 同标签 8/9/2025

Lang.Avalonia: Avalonia's multi-language solution seamlessly supports three formats: Resx/XML/JSON

This is a multi-language management library specially designed for the Avalonia framework. It reconstructs the multi-language support logic through plug-in architecture. It is not only compatible with traditional Resx resource files, but also adds support for XML and JSON formats. It also provides type-safe resource references, dynamic language switching and other capabilities make multi-language development simpler and more efficient.

继续阅读