How to pass azure pipelines dotnet inputs to the linux dotnet binary - linux

I am trying to replicate the following Azure pipeline using the CLI dotnet command:
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
So far, I can make the project build, but getting a zip file out of it seems problematic - passing the inputs zipAfterPublish etc appears impossible to pass, although, there is some scattered documentation suggesting these can be passed with -p:"optiona=x;optionb=y" or /p:"optiona=x;optionb=y". I can find no definitive documentation on this.
This is what I have - the build part works, the $PWD/out directory is populated with many files but nothing is zipped:
dotnet publish --configuration Release --output $PWD/out /p:"zipAfterPublish=true;publishWebProjects=true"
I'm guessing this is around how to pass the inputs ( https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops ) correctly to the command.

I am trying to replicate the following Azure pipeline using the CLI
dotnet command:
1.The zipAfterPublish is one option available only in Dotnet Publish task. If you check the log of dotnet publish task, you'll find it doesn't pass any property like zipAfterPublish to the command:
Since only the msbuild property can be passed in this way: /p:xxx=xxx. The zipAfterPublish won't work in command-line as it's not msbuild property, that option is not supported in dotnet cli, only available in Azure Devops Dotnet Publish task.
2.Normally if we want to publish one .net core web project and zip it after publish using dotnet cli locally, we can use command like:
dotnet publish xx.csproj /nologo /p:PublishProfile=xxx /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform=xxx /p:configuration=xxx /p:DesktopBuildPackageLocation=SomePath\xxx.zip
Or
dotnet build xxx.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\Some\Path\package" /p:OutDir="C:\Some\Path\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\Some\Path\package\package.zip"
Which is described in this issue.
Above commands can work in windows to generate a xx.zip folder.
However:
It seems that you're in linux environment, please check this document. If you want to zip the publish folder(generate a package), the dotnet build/publish will call msdeploy.exe to do this job, but since MSDeploy lacks cross-platform support, the following MSDeploy options are supported only on Windows. So dotnet cli command is not supported to generate zip after publish in linux environment... What you want is not supported for now in Linux.
Possible workaround:
Since we can use dotnet publish to publish the project to one folder(Folder works cross-platform), we can call another zip command after dotnet publish to zip it ourselves.
Hope my answer helps to resolve your puzzle :)

Related

Run dotnet tests without excluding ExcludeFromCoverageAttribute (i.e. consider all code coverable)

I am running test using dotnet test (dotnet SDK version: 6.0.402)
the command looks like this
"C:/Program Files/dotnet/dotnet.exe" test "D:\MyRepo\MyProj.csproj" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:SolutionDir=D:\MyRepo --configuration Release --logger "trx;logfilename=MyProj.UnitTest.csproj.trx" --no-build --no-restore --results-directory="testOutput"
I am not providing a .runsettings file at the moment.
Now, I'd like the execution to bypass the behaviour of ExcludeFromCoverageAttribute. In other words, I want cobertura to consider all code coverable, even that annotated with ExcludeFromCoverageAttribute
I've tried passing my own .runsettings file with a datacollector that didn't exclude such attribute, but it doesn't seem to be making a difference
Is there a way to achieve what I am trying to do?

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

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.
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)

Trigger a specific project inside a repository when creating a build in Azure build pipeline

I have one repository with 3 branches dev, test and prod. I have a Visual Studio solution with 3 projects in it. One Angular, a worker service and ASP.NET web api project. So that whole solution in one repository.
I have pushed everything to dev branch. So when creating the build pipeline I chose ASP.NET core and then on writing the build yaml, in the trigger I specified Dev branch
trigger : - dev
But how can I specify which project to build among the 3 project in that repository to build? My plan is to build the ASP.NET core web api to build.
Also I need another build for the angular as well..
This will be in your build task:
steps:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '**/*.csproj' # Update this to match your need
arguments: '--configuration $(buildConfiguration)'
The project path will be different for your various projects

Azure Pipeline for Xamarin Forms iOS Fails at Nuget Restore

I have searched everywhere all day long trying to get this pipeline to work.
It starts the pipeline and my tasks seem to run fine right up until I hit nuget restore for my solution. It fails with:
Unable to locate executable file: 'mono'
I have no idea why this is happening. I am using the macOS-latest vm image and I am using this task to set the mono version:
- task: Bash#3
inputs:
targetType: 'inline'
script: |
SYMLINK=6_8_0_123
MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
Is there something else I can set to make Nuget find the mono library?
Thanks.
Azure Pipeline for Xamarin Forms iOS Fails at Nuget Restore
According to the error message:
Unable to locate executable file: 'mono'
It seems the NuGet task hasn't been implemented to work on that agent (macOS-latest) at this moment.
To resolve above error, we could use the .NET Core (dotnet restore) task instead of nuget restore task.
The final solution for this specific case:
Thanks to jmichas for sharing. Use the .NET Core (dotnet restore) task indeed resolve that error. But, it brought an onslaught of other errors in specific case. The final solution for this specific case is that use the runNugetRestore in the xamarin ios build task:
- task: XamariniOS#2
inputs:
runNugetRestore: true
Hope this helps others.

How to build a web app MVC5-WEB API 2 in Azure Devops with CLI?

I want to build a web app (web api 2) in Azure but i don't want to obtain a zip, i just want to get a directory with all necessary files. I don't know the command line to do that.
I don't want to use the classical deploy web app task because i need to add additional files after the build. Thanks in advance for your help.
How to build a web app MVC5-WEB API 2 in Azure Devops with CLI?
You could use Visual Studio Build task with MSBuild Arguments:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish
to publish web app to artifact folder or any other folder you want.
You also can specify the publish profile directly:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:PublishProfile="{publish profile name}";publishUrl="$(build.artifactstagingdirectory)"
With FileSystem publish method, the published files are in a folder, not zipped.
And if you want use the command line task instead of Visual Studio Build task, you could invoke MSBuild.exe with same MSBuild Arguments to build this solution/project:
"<PathForMSBuild.exeOnYourAgent>\MSBuild.exe" "<YourProject/SolutionPath>" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish
If you want to add additional files after the build, you could add a task after Visual Studio build task, or you can create AfterBuild Target in your project to add additional files.
Hope this helps.

Resources