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.