GitHub actions部署了错误版本的Newtonsoft.到Azure的Json nuget包



我有一个GitHub行动做。net解决方案的构建,测试和部署到Azure:

name: Build and deploy ASP.Net Core app to Azure Web App - project-test-api
on:
push:
branches:
- main
workflow_dispatch:
env:
# Stop wasting time caching packages
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending usage data to Microsoft
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: AutoModality/action-clean@v1
- uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
- name: Manually restore
working-directory: SolutionDir
run: dotnet restore --force
- name: Build with dotnet
working-directory: SolutionDir
run: dotnet build --configuration Release --no-restore

- name: Test
working-directory: SolutionDir
run: dotnet test --no-restore --no-build --configuration Release
- name: dotnet publish
working-directory: SolutionDir
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'quickplanner-test-api'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_SECRET }}
package: .

最近我在解决方案中添加了一个测试项目。从我所看到的,测试项目中使用的一个软件包使用了Newtonsoft。Json v9.0,而解决方案的其余部分使用v13.0。解决方案可以在本地构建、测试,一切都没问题。GitHub操作还会成功完成解决方案的构建、运行测试并将其部署到Azure。问题发生在Azure上- GitHub操作使用旧版本的Newtonsoft.Json。所有的项目都期待更新,所以整个网站因为这个而崩溃。我不知道如何解决这个问题-我试过手动添加Newtonsoft的正确版本。Json到测试项目,到所有项目,清除GitHub行动中的缓存,但没有运气。工作只是从解决方案中删除测试项目,但显然我希望测试能够工作。有人知道为什么这个坏了,如何修复它吗?

我设法通过将以下代码添加到我的测试项目csproj文件来解决此问题:

<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

我不完全确定这个问题背后的根本原因是什么

最新更新