C#项目中的Nuget软件包如何从Azure伪像的饲料中参考和使用GitHub动作部署

发布于 2025-01-21 14:34:21 字数 3665 浏览 2 评论 0原文

我创建了一个大型Web组装项目,该项目引用了一个软件包,该软件包位于外部Nuget源(Azure trifact feed)中。

我用Azure创建了提要。 ✅
我成功地将图书馆/外部软件包的 *.nupkg上传到azure feed✅
我创建了一个个人访问令牌-Pat in Azure-用于githhub✅
我在当地与Visual Studio一起测试并起作用✅

,但是该项目不使用GitHub Action进行编译
我在使用PAT值的GitHub项目配置中创建了一个秘密。 ✅

错误

Successfully installed workload(s) wasm-tools.

  Determining projects to restore...
/github/workspace/Insta3D.MainSite/Insta3D.MainSite.csproj : error NU1101: Unable to find package Insta3D.Common. No packages exist with this id in source(s): nuget.org
  Failed to restore /github/workspace/Insta3D.MainSite/Insta3D.MainSite.csproj (in 1.58 sec).

我的github工作流动。

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - main
env:
  AZURE_FEED_NAME: Insta3DNugetFeed
  AZURE_FEED_SOURCE: "https://pkgs.dev.azure.com/Insta3D/Insta3D/_packaging/Insta3DNugetFeed/nuget/v3/index.json"
  BUILD_CONFIGURATION: 'Release'    # set this to the appropriate build configuration
  DOTNET_VERSION: '6.x'
jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Restore packages
        run: |
          pwsh -NoLogo -ExecutionPolicy Bypass -Command "./AddNugetSource.ps1 -FeedName ${{ env.AZURE_FEED_NAME }} -FeedSource ${{ env.AZURE_FEED_SOURCE }} -AzurePAT ${{ secrets.AZURE_Insta3D_READ_PAT }}"
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PURPLE_WAVE_0AF3AD50F }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: "Insta3D.MainSite" # App source code path
          api_location: "api" # Api source code path - optional
          output_location: "wwwroot" # Built app content directory - optional
          ###### End of Repository/Build Configurations ######

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PURPLE_WAVE_0AF3AD50F }}
          action: "close"

addNugetSource.ps1

[CmdletBinding()]
param (
    [Parameter()]
    [string]
    $FeedName,

    [Parameter()]
    [string]
    $FeedSource,

    [Parameter()]
    [string]
    $AzurePAT
)

$ErrorActionPreferenceOriginal = $ErrorActionPreference
try {
    $ErrorActionPreference = "Ignore"
    dotnet nuget remove source $FeedName 2>&1
    dotnet nuget add source "$FeedSource" --name "$FeedName" --username az --password "$AzurePAT" --store-password-in-clear-text
    dotnet restore "Insta3D.MainSite.sln"
}
finally {
    $ErrorActionPreference = $ErrorActionPreferenceOriginal
}

I created a Blazor Web Assembly project, this project references a package, this package resides in an external nuget source(Azure artifact feed).

I created the feed in Azure. ✅
I successfuly upload the *.nupkg of the library/external package to Azure feed ✅
I created a Personal Access Token - PAT in Azure - for use in GitHhub ✅
I tested with Visual Studio locally and works ✅

but the project not compile with Github Actions
I created a secret in my Github project configuration with the PAT value. ✅

Error

Successfully installed workload(s) wasm-tools.

  Determining projects to restore...
/github/workspace/Insta3D.MainSite/Insta3D.MainSite.csproj : error NU1101: Unable to find package Insta3D.Common. No packages exist with this id in source(s): nuget.org
  Failed to restore /github/workspace/Insta3D.MainSite/Insta3D.MainSite.csproj (in 1.58 sec).

My Github workflow action.

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - main
env:
  AZURE_FEED_NAME: Insta3DNugetFeed
  AZURE_FEED_SOURCE: "https://pkgs.dev.azure.com/Insta3D/Insta3D/_packaging/Insta3DNugetFeed/nuget/v3/index.json"
  BUILD_CONFIGURATION: 'Release'    # set this to the appropriate build configuration
  DOTNET_VERSION: '6.x'
jobs:
  build_and_deploy_job:
    if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
    runs-on: ubuntu-latest
    name: Build and Deploy Job
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
      - name: Restore packages
        run: |
          pwsh -NoLogo -ExecutionPolicy Bypass -Command "./AddNugetSource.ps1 -FeedName ${{ env.AZURE_FEED_NAME }} -FeedSource ${{ env.AZURE_FEED_SOURCE }} -AzurePAT ${{ secrets.AZURE_Insta3D_READ_PAT }}"
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PURPLE_WAVE_0AF3AD50F }}
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: "Insta3D.MainSite" # App source code path
          api_location: "api" # Api source code path - optional
          output_location: "wwwroot" # Built app content directory - optional
          ###### End of Repository/Build Configurations ######

  close_pull_request_job:
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    runs-on: ubuntu-latest
    name: Close Pull Request Job
    steps:
      - name: Close Pull Request
        id: closepullrequest
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_PURPLE_WAVE_0AF3AD50F }}
          action: "close"

AddNugetSource.ps1

[CmdletBinding()]
param (
    [Parameter()]
    [string]
    $FeedName,

    [Parameter()]
    [string]
    $FeedSource,

    [Parameter()]
    [string]
    $AzurePAT
)

$ErrorActionPreferenceOriginal = $ErrorActionPreference
try {
    $ErrorActionPreference = "Ignore"
    dotnet nuget remove source $FeedName 2>&1
    dotnet nuget add source "$FeedSource" --name "$FeedName" --username az --password "$AzurePAT" --store-password-in-clear-text
    dotnet restore "Insta3D.MainSite.sln"
}
finally {
    $ErrorActionPreference = $ErrorActionPreferenceOriginal
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文