3

I would like to automate my deployment. So far, I've been manualy publishing my Net Core 3.1 solution through Visual Studio 2019 with no problems. Hovewer, when I want to use Azure DevOps Pipeline, even though I received no errors, I always end up with hundreds of .dll files instead of one .exe file.

This is my Visual Studio configuration that works as intended:

<?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>

As you can see, it's single file and self contained.

This is my yaml file on DevOps:

    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'

The pipeline works and publish application successfully, hovewer, it is not single file. Any idea what might cause the trouble?

Small note about the pipeline: I am using two MSBuilds, because I've not been able to find better workaround for problem with publishing single file applications from solution that has multiple projects.

When I try to publish the solution, I got following error for each .csproj file:

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

That's why I am publishing whole solution first and then only ApmBackend.csproj, which is executible. Not very clean, but it works and I don't know any other fix.

2
  • Instead of using the MSBuild task, try using the DotNetCoreCLI task. 1st with command: restore, 2nd with command: buld, 3rd with command: publish and arguments: --self-contained true. Commented Aug 17, 2020 at 6:57
  • Yes, that's how I solved the problem in the end. Still no idea why MSBuild didn't work Commented Aug 17, 2020 at 13:15

1 Answer 1

3

For anyone trying to produce single exe on azure in the future, this is yaml that actually works (I am positive there is a cleaner, more straightforward solution, but I wasn't able to find it):

# 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://learn.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'
    

You of course have to replace ApmBackend.csproj with you own executable project

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.