微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我有一个目标框架为 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 核心版本来构建这个项目?

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

谢谢, 啊

解决方法

.NET Core is different as compared to .NET Framework

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

# 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 的分步教程。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。