Azure部署失败,’dotnet publish’ 项目文件不存在。

huangapple go评论57阅读模式
英文:

Azure deploy failed 'dotnet publish' project file does not exist

问题

I have a .NET API running on Azure that I am attempting to upgrade from .NET Core 3.1 to .NET 7.0. When I attempted to deploy my updated .csproj file with the <TargetFramework> update and <PackageReference> version updates, the deploy to Azure (via push to remote master branch) failed on the dotnet publish step. I recently updated my GitHub action yaml file to update actions/setup-dotnet@v3 and actions/checkout@v3, and the jobs section of that file now looks like this:

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - name: Set up .NET Core
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '7.x'
        include-prerelease: true

    - name: Build with dotnet
      run: dotnet build --configuration Release

    - name: dotnet publish
      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

The error I get in Azure is the following:

Run dotnet publish -c Release -o C:\Program Files\dotnet/myapp
  dotnet publish -c Release -o C:\Program Files\dotnet/myapp
  shell: C:\Program Files\PowerShell\pwsh.EXE -command "& '{0}'"
  env:
    DOTNET_ROOT: C:\Program Files\dotnet
MSBuild version 17.5.1+f6fdcf537 for .NET
MSBUILD : error MSB1009: Project file does not exist.
Switch: Files\dotnet/myapp
Error: Process completed with exit code 1.

I am very inexperienced with dev ops and I would be happy to provide more detail if needed.

英文:

I have a .NET API running on Azure that I am attempting to upgrade from .NET Core 3.1 to .NET 7.0. When I attempted to deploy my updated .csproj file with the &lt;TargetFramework&gt; update and &lt;PackageReference&gt; version updates, the deploy to Azure (via push to remote master branch) failed on the dotnet publish step. I recently updated my GitHub action yaml file to update actions/setup-dotnet@v3 and actions/checkout@v3 and the jobs section of that file now looks like this

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - name: Set up .NET Core
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: &#39;7.x&#39;
        include-prerelease: true

    - name: Build with dotnet
      run: dotnet build --configuration Release

    - name: dotnet publish
      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

The error I get in Azure is the following

Run dotnet publish -c Release -o C:\Program Files\dotnet/myapp
  dotnet publish -c Release -o C:\Program Files\dotnet/myapp
  shell: C:\Program Files\PowerShell\pwsh.EXE -command &quot;. &#39;{0}&#39;&quot;
  env:
    DOTNET_ROOT: C:\Program Files\dotnet
MSBuild version 17.5.1+f6fdcf537 for .NET
MSBUILD : error MSB1009: Project file does not exist.
Switch: Files\dotnet/myapp
Error: Process completed with exit code 1.

I am very inexperienced with dev ops and I would be happy to provide more detail if needed.

答案1

得分: 0

以下更改解决了我的问题:

  • dotnet publishrun行上,将正斜杠更改为反斜杠
  • 在整个文档中,将${{env.DOTNET_ROOT}}替换为${{env.GITHUB_WORKSPACE}}
  • dotnet publishrun行上,用引号括起路径

新的部分文件:

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - name: Set up .NET Core
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '7.x'
        include-prerelease: true

    - name: Build with dotnet
      run: dotnet build --configuration Release

    - name: dotnet publish
      run: dotnet publish -c Release -o "${{env.GITHUB_WORKSPACE}}\myapp"

    - name: Upload artifact for deployment job
      uses: actions/upload-artifact@v3
      with:
        name: .net-app
        path: ${{env.GITHUB_WORKSPACE}}\myapp
英文:

The following changes fixed my problem:

  • Change forward slash to backslash on run line of dotnet publish
  • Swap ${{env.DOTNET_ROOT}} with ${{env.GITHUB_WORKSPACE}} throughout document
  • Surround path with quotes on run line of dotnet publish

New file partial:

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v3

    - name: Set up .NET Core
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: &#39;7.x&#39;
        include-prerelease: true

    - name: Build with dotnet
      run: dotnet build --configuration Release

    - name: dotnet publish
      run: dotnet publish -c Release -o &quot;${{env.GITHUB_WORKSPACE}}\myapp&quot;

    - name: Upload artifact for deployment job
      uses: actions/upload-artifact@v3
      with:
        name: .net-app
        path: ${{env.GITHUB_WORKSPACE}}\myapp

huangapple
  • 本文由 发表于 2023年5月13日 23:52:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76243649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定