C#项目中的Nuget软件包如何从Azure伪像的饲料中参考和使用GitHub动作部署
我创建了一个大型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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论