我可以在 Azure DevOps 中使用 dotnet publish 命令发布 .net Framework 4.7.1 解决方案吗

Can I publish .net framework 4.7.1 solution with dotnet publish command in Azure DevOps

我有一个目标框架为 4.7.1 的解决方案。 我已经在本地安装了 dotnet core sdks 并且能够发出构建、发布命令。

我的项目文件看起来像这样,其中有很多对 dotnet 核心 dll 的引用

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net471</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.3.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.4.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.3.0" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0">

我在尝试使用特定的 .net sdk 构建此解决方案时在 Azure DevOps yaml 中遇到错误。

    - task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '2.x'
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    workingDirectory: '$(solution)'

错误显示为 There was an error when attempting to execute the process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe'. This may indicate the process failed to start. Error: spawn C:\hostedtoolcache\windows\dotnet\dotnet.exe

更重要的是,我不确定我应该使用哪个 dotnet core 版本来构建这个项目?

在本地,我有 dotnet 5 sdk 并且能够使用 dotnet publish 命令成功发布。 我应该在 DevOps 中理想地使用哪些命令来构建 net471 项目?

谢谢, AK

.NET Core is different as compared to .NET Framework.

此外,如果您想为 .NET Framework 项目创建管道,您不能使用 .NET Core 任务。 PipelineYAML 文件应如下所示:

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish artifacts'
  inputs:
    PathtoPublish: $(build.artifactstagingdirectory)
    ArtifactName: 'PublishBuildArtifacts'

    

请参阅此 here 的分步教程。