有很多关于dotnet.exe nuget.exe和Chocolatey的全面而详细的文档,但我没有找到关于一个常见需求的简单明了的教程:将 .NET Core 控制台应用程序推送到私有 Nuget 存储库并安装它巧克力味。来了一个。
$version = "1.2.3"
$apiKey = "1234123412341234"
$repository = "https://your.repository.manager:8081/repository/repo-name/"
Run Code Online (Sandbox Code Playgroud)
<path to your project>\bin\Release\netcoreapp2.2\publish.dotnet publish -c Release /p:version=$version
Run Code Online (Sandbox Code Playgroud)
<?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>
Run Code Online (Sandbox Code Playgroud)
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]"
Run Code Online (Sandbox Code Playgroud)
进而chocolateyuninstall.ps1:
$ErrorActionPreference = 'Stop'
Uninstall-BinFile [executable name, e.g. my-tool]
Run Code Online (Sandbox Code Playgroud)
choco pack "[path to your nuspec file created in step 3]" --version $version
Run Code Online (Sandbox Code Playgroud)
choco push "[path to the nuget package created in step 5]" -k $apiKey -s $repository
Run Code Online (Sandbox Code Playgroud)
*--force如果您的私人 nuget 存储库不在 https 后面,请添加
choco upgrade [your package id] -y -s $repository
Run Code Online (Sandbox Code Playgroud)
现在已经准备好了!您可以使用文件中定义的可执行文件名称来运行它chocolateyinstall.ps1,例如my-tool --version.
| 归档时间: |
|
| 查看次数: |
782 次 |
| 最近记录: |