gpt4 book ai didi

nuget - 如何将 .net 核心控制台应用程序发布到(私有(private))nuget 存储库并使用巧克力安装它?

转载 作者:行者123 更新时间:2023-12-03 16:51:17 25 4
gpt4 key购买 nike

有很多关于 dotnet.exe 的全面而详细的文档。 nuget.exechocolatey但是我没有找到关于一个常见需求的简单而简洁的教程:将 .NET Core 控制台应用程序推送到私有(private) Nuget 存储库并使用 Chocolatey 安装它。来了一个。

最佳答案

  • 定义环境变量以更容易地传递值(替换为实际值):

  • $version = "1.2.3"
    $apiKey = "1234123412341234"
    $repository = "https://your.repository.manager:8081/repository/repo-name/"
  • 构建并发布您的应用程序。这将创建类似于 <path to your project>\bin\Release\netcoreapp2.2\publish 的 DLL(和其他项目项)。 .

  • dotnet publish -c Release /p:version=$version
  • 创建 nuspec 文件(替换方括号中的值):

  • <?xml version="1.0"?>
    <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
    <metadata>
    <id>[your package id]</id>
    <version>$version$</version>
    <title>[your package title]</title>
    <authors>[author(s)]</authors>
    <owners>[owner(s)]</owners>
    <projectUrl>[project url e.g. containing documentation]</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>[description]</description>
    <copyright>[copyright]</copyright>
    </metadata>
    <files>
    <file src="chocolateyinstall.ps1" target="tools" />
    <file src="chocolateyuninstall.ps1" target="tools" />
    <file src="[path to the publish directory from step 2]\**" target="tools" />
    </files>
    </package>
  • 创建安装文件。 Chocolatey 将使用这些来安装和卸载您的应用程序。一、chocolateyinstall.ps1 :

  • $ErrorActionPreference = 'Stop'

    $toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
    $defaultDotnetRuntimePath = "C:\Program Files\dotnet\dotnet.exe"

    if (!(Test-Path $defaultDotnetRuntimePath))
    {
    Write-Host -ForegroundColor Red "File not found: $defaultDotnetRuntimePath"
    Write-Host "The package depends on the .NET Core Runtime (dotnet.exe) which was not found."
    Write-Host "Please install the latest version of the .NET Core Runtime to use this package."
    exit 1
    }

    Install-Binfile -Name [executable name, e.g. my-tool] -Path "$defaultDotnetRuntimePath" -Command "$toolsDir\[name of your main dll, e.g. My.Awesome.Cli.Program.dll]"

    然后 chocolateyuninstall.ps1 :

    $ErrorActionPreference = 'Stop'

    Uninstall-BinFile [executable name, e.g. my-tool]
  • 创建 nuget 包:

  • choco pack "[path to your nuspec file created in step 3]" --version $version
  • 将您的包推送到存储库:

  • choco push "[path to the nuget package created in step 5]" -k $apiKey -s $repository

    *添加 --force如果您的私有(private) nuget 存储库不在 https 后面
  • 使用 Chocolatey 安装(或升级)您的程序:

  • choco upgrade [your package id] -y -s $repository

    现在准备好了!您可以使用 chocolateyinstall.ps1 中定义的可执行文件名运行它。文件,例如 my-tool --version .

    关于nuget - 如何将 .net 核心控制台应用程序发布到(私有(private))nuget 存储库并使用巧克力安装它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54727569/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com