簡體   English   中英

Azure DevOps 管道未從 Net Core 3.1 應用程序生成單個文件 exe

[英]Azure DevOps Pipeline not producing single file exe from Net Core 3.1 application

我想自動化我的部署。 到目前為止,我一直在通過 Visual Studio 2019 手動發布我的 Net Core 3.1 解決方案,沒有任何問題。 然而,當我想使用 Azure DevOps Pipeline 時,即使我沒有收到任何錯誤,我最終還是會得到數百個 .dll 文件而不是 one.exe 文件

這是我按預期工作的 Visual Studio 配置:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>C:\Users\Karel Křesťan\Desktop\apm-local</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishSingleFile>True</PublishSingleFile>
    <ProjectGuid>870788a8-f14a-4683-8395-6048e2c9aa1e</ProjectGuid>
    <SelfContained>true</SelfContained>
  </PropertyGroup>
</Project>

如您所見,它是單個文件且自包含的 .

這是我在 DevOps 上的 yaml 文件:

    trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  imageName: 'fine-project-manager'

steps:
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.1.107'

- task: MSBuild@1
  inputs:
    solution: '**/*.sln'
    msbuildArguments: '/t:restore;rebuild;publish /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SelfContained=true /p:Platform="Any CPU" /p:Configuration=Release /p:RuntimeIdentifier=win-x64'
    msbuildVersion: latest

- task: MSBuild@1
  inputs:
    solution: '**/*.sln'
    msbuildArguments: '/T:"ApmBackend" /t:publish /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SelfContained=true /p:Platform="Any CPU" /p:Configuration=Release /p:PackageAsSingleFile=true /p:RuntimeIdentifier=win-x64 /p:OutputPath=$(Build.ArtifactStagingDirectory)'
    msbuildVersion: latest

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'publish'
    publishLocation: 'Container'

管道工作並成功發布應用程序,但是,它不是單個文件 知道什么可能導致麻煩嗎?

關於管道的小提示:我正在使用兩個 MSBuild,因為我無法找到更好的解決方法來解決從具有多個項目的解決方案發布單個文件應用程序的問題。

當我嘗試發布解決方案時,每個.csproj 文件出現以下錯誤:

error NETSDK1099: Publishing to a single-file is only supported for executable applications.

這就是為什么我首先發布整個解決方案,然后只發布可執行的 ApmBackend.csproj。 不是很干凈,但它有效,我不知道有任何其他修復方法。

對於將來試圖在 azure 上生成單個 exe 的任何人,這是實際有效的 yaml(我很肯定有一個更清潔、更直接的解決方案,但我找不到它):

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  imageName: 'fine-project-manager'

steps:
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '3.1.107'

- task: MSBuild@1
  inputs:
    solution: '**/*.sln'
    msbuildArguments: '/t:restore;rebuild;publish /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SelfContained=true /p:Platform="Any CPU" /p:Configuration=Release /p:RuntimeIdentifier=win-x64'
    msbuildVersion: latest

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    arguments: -c Release --runtime win-x64 /p:PublishSingleFile=true --self-contained --output $(Build.ArtifactStagingDirectory) --no-dependencies
    projects: $(Build.SourcesDirectory)\ApmBackend\ApmBackend.csproj
    zipAfterPublish: false

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'publish'
    publishLocation: 'Container'
    

您當然必須用您自己的可執行項目替換 ApmBackend.csproj

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM