【发布时间】:2023-02-15 09:40:32
【问题描述】:
我正在尝试设置我的“第一个”GitHub 操作,以将 .NET 库的 NuGet 包发布到我的私人 GitHub Packages 注册表。
我希望我的操作从 .csproj 文件中获取包的版本号。我正在尝试按照此处的说明进行操作,但看起来他们对版本号进行了硬编码:
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry
如何从.csproj 文件中获取版本号?
到目前为止,这是我的release.yml 文件:
name: Publish MyApp NuGet to GitHub Packages
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create NuGet package
run: dotnet pack --configuration Release
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Publish to GitHub Packages
run: dotnet nuget push "bin/Release/MyApp.1.0.0.nupkg" --source "github"
这是nuget.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<packageSources>
<clear />
<add key="github" value="https://nuget.pkg.github.com/MY_GITHUB_COMPANY_ACCOUNT/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="MY_GITHUB_USERNAME" />
<add key="ClearTextPassword" value="MY_GITHUB_PERSONAL_ACCESS_TOKEN" />
</github>
</packageSourceCredentials>
</configuration>
这是 .csproj 文件中我定义包相关信息的部分:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>MyCompany, LLC</Authors>
<Company>MyCompany, LLC</Company>
<Description>MyApp Library</Description>
<Version>1.2.1</Version>
<RepositoryUrl>https://github.com/MY_GITHUB_COMPANY_ACCOUNT/my-app</RepositoryUrl>
<Copyright>MyCompany, LLC (c) 2015 - 2023</Copyright>
</PropertyGroup>
【问题讨论】:
标签: .net github nuget github-actions github-package-registry