c# - 我可以在 Azure DevOps 中使用 dotnetpublish 命令发布 .net Framework 4.7.1 解决方案吗

标签 c# azure azure-devops .net-framework-version .net-4.7.1

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

我的项目文件如下所示,其中有许多对 dotnet core 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)'

错误内容为尝试执行进程“C:\hostedtoolcache\windows\dotnet\dotnet.exe”时出错。这可能表明该进程未能启动。错误:生成 C:\hostedtoolcache\windows\dotnet\dotnet.exe

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

在本地,我有 dotnet 5 sdk,并且能够使用 dotnet 发布命令成功发布。 我应该在 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://learn.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 .

关于c# - 我可以在 Azure DevOps 中使用 dotnetpublish 命令发布 .net Framework 4.7.1 解决方案吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65391555/

相关文章:

c# - 如何在第一次调用 .NET dll 时运行方法?

azure - 无法使用 terraform/programmatic 将 Azure Key Vault 与 databrick 集成

azure - 无法使用我的 Microsoft 帐户使用 Active Directory 登录我的测试应用程序

nuget - 恢复包时 dotnet build 命令失败

xml - 模糊搜索FIELD azure中的全局列表

c# - 混合模式程序集是针对版本 'v1.1.4322' 构建的

c# - .NET 类库中的 HTML 编码

c# - ASP .Net 从 SQL Server Compact 数据库获取当前用户 ID

Azure 通知中心 : Count is not updated in Active Device limit count after delete registration from backend

c# - AzureDevOps 上的 TF.exe 和 TfSecurity.exe 身份验证