How to compile .NET (console application) in Azure DevOps and generate an exe

Viewed 8412

I created a pipeline using the .NET desktop template and using the 'create .msi' extension but it shows a warning:

 ##[warning]No .MSI files were found, please check your build-configuration. If this is expected, you might consider to use the default Visual Studio Build task instead of this custom Installer task.
2018-11-28T22:58:54.1434410Z ##[section]Finishing: Create .msi file(s) from VS Installer project(s).

Anyone know how can I achieve creating an exe file using an Azure Pipeline and deploy it on a Virtual Machine.

1 Answers

If you use .NET Core CLI task to build your console app.

Below dotnet publish arguements commmand will generate .exe file. See this thread for more information.

dotnet publish -r win-x64 -p:PublishSingleFile=True --self-contained false

So you can add above arguments to your .NET Core CLI task. See below yaml pipeline.

- task: DotNetCoreCLI@2
  inputs:
    command: publish 
    arguments: -r win-x64 -p:PublishSingleFile=True --self-contained false -o $(Build.ArtifactStagingDirectory)
    projects: '**/*.csproj'
    publishWebProjects: false
  enabled: true

Above DotNetCoreCLI task will output the .exe file to folder $(Build.ArtifactStagingDirectory) (ie. C:\agent\_work\1\a)

If you use Visual Studio Build task to build your console app.

You can first add below <PublishSingleFile> and <RuntimeIdentifier> properties to the .csproj file of your project.

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <PublishSingleFile>True</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

Then set the msbuildArgs of the Visual Studio Build task in your pipeline as below:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    msbuildArgs: '/t:publish /p:PublishSingleFile=True /p:RuntimeIdentifier=win-x64 /p:outputpath=$(Build.ArtifactStagingDirectory)\'

Then Vsbuild task will output the .exe file to folder $(Build.ArtifactStagingDirectory) specified in /p:outputpath (ie. C:\agent\_work\1\a)

Related