Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to quickly and automatically package Nuget multi-platform and multi-target

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Nuget multi-platform multi-target how to quickly automatically package, for this problem, this article details the corresponding analysis and solution, hoping to help more small partners who want to solve this problem find a simpler and easier way.

Nuget is essential for building modern. Net applications, and packaging Nuget quickly is an effective way to increase productivity.

1. pre-conditions

In order to achieve fast packaging of Nuget, we need to solve some pre-dependencies, whether it is. Net Framework, Mono or. Net Standard (. Net Core), we need to compile it first, then package it into Nuget package, and finally publish it to Nuget server.

Related goals (supporting platforms and dependencies):

.Net Framework (Windows only) : MSBuild.exe, Nuget.exe

Mono (cross-platform) : mono, xbuild, Nuget.exe

. Net Standard (cross-platform) : dotnet sdk

Since most people are still developing on Windows, my tutorial below will be Windows standard and sidetracked to other platforms.

2. Quick Packaging Sample 2.1 Quick Packaging in Visual Studio

In Visual Studio to achieve rapid packaging Nuget is mainly with the help of Visual Studio comes with external tools. Before we go into battle, we need to make sure our dependencies are met. Since Visual Studio is already installed, MSBuild and Nuget are installed by default.

Second, in order to save as much space as possible in the string of the auto-packaged script, we try to add the corresponding dependency to the Path path of the system environment variable. Generally speaking, Msbuild is in the Msbuild directory under the Visual Studio installation directory, as shown in the following figure, in my local machine address is "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64", Nuget is best placed separately, for example, I put it in the "D:\tools" directory.

If you're careful enough, you'll notice that after installing the. Net Core SDK, it's added to the system's environment variables by default ( Mono as well).

Then we use Visual Studio to open the corresponding project, click on "Tools-External Tools" in the menu bar, and add our custom automatic package publishing script.

As shown in the figure above, powershell.exe is used here. If powershell.exe is not found, the path is also added to the path of the system environment variable. As for parameters, it can be a ps script file or an execution script statement, which is used here. Initial directory Select "target directory" or "project directory" can be.

As you can see from the figure above, there is a distinction between target builds, where the build scripts for. Net Framework and. Net Standard are distributed, where the. Net Framework looks like this:

del *.nupkg ; $roj=dir *.csproj ;msbuild $roj; nuget pack $roj ; $nupkg= dir *.nupkg; nuget.exe push $nupkg nugetpassword -Source http://192.168.9.1/nuget

The. Net Standard is:

del *.nupkg ; dotnet build ;dotnet pack --output $pwd;$nupkg= dir *.nupkg; dotnet nuget push $nupkg nugetpassword -Source http://192.168.9.1/nuget

For Mono running on non-Windows it might be:

rm *.nupkg ; $roj= *.csproj ;xbuild $roj; $ver= date -d yesterday +%Y%m%d%H%M;nuget pack $roj -Suffix $ver; $nupkg= *.nupkg; mono nuget.exe push $nupkg nugetpassword -Source http://192.168.9.1/nuget

Their common feature is to delete the nupkg file in the current path, then compile, package, and publish. (If you don't have a private Nuget server, you can refer to my other article)

More extensions can be made on this basis, such as releasing a beta version, adding suffixes to the original basis, such as:

del *.nupkg ; $roj=dir *.csproj ;msbuild $roj; $ver=\"beta-\"+(Get-Date).ToString(\"yyyyMMddHHmm\");nuget pack $roj -Suffix $ver; $nupkg= dir *.nupkg; nuget.exe push $nupkg nugetpassword -Source http://192.168.9.1/nuget

After writing a custom external tool, you can press a button every time you package a contract.

2.2 VSCode

VSCode is another popular code editor that does not currently support external tools in Visual Studio (please let me know if there is), nor does it have extensions to support direct Nuget package publishing, but that does not prevent us from quickly automating packaging and publishing Nuget packages.

A powerful feature in VSCode is the task feature, which we can perform to achieve the same effect.

2.3 Folder right-click menu

Sometimes we may need to run scripts outside the ide, and the folder right-click menu is very efficient.

The specific operation is to modify the windows registry, specific reference windows how to modify the right-click menu article.

About Nuget multi-platform multi-target how to quickly automatically package the answer to the question shared here, I hope the above content can have some help for everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report