Should I put my custom build steps in MSBuild or TFS/Azure DevOps Build pipelines? - tfs

Is MSBuild being deprecated in favor of TFS/Azure DevOps Build pipelines? I have some custom build steps I need to add, such as obfuscating code and computing file hashes. I'm not sure if I should add them as a custom target in my MSBuild/csproj file or if they should be separate steps in a build pipeline. Has Microsoft provided any guidance about which one to use and/or are there common best practices used by the .NET community?
What are the pros/cons of doing custom build steps in MSBuild vs as a build pipeline step?

No, it's not deprecated. Build pipelines are just glorified task runners. All those pipelines do is run your MSBuild script; they don't actually "build" anything in the same sense that MSBuild builds things.
That said, here are some scenarios where it makes sense to add additional build targets and conditions to an MSBuild file:
It needs to happen during local development
It needs to happen across multiple CI solutions (i.e. Jenkins, TeamCity, Azure DevOps)
You foresee switching to a different CI solution in the future
That should make the pros of MSBuild pretty obvious. It's going to work anywhere you build your application, including on your local desktop, and it's going to be portable. It also has the advantage of being automatically tracked by version control, which (unless you're using YAML build), Azure DevOps builds are not.

Related

How to build only a specific project with DevOps Pipelines

Is this possible to build only a single project and its dependencies specified in a pipeline script?
If I have a Visual Studio Solution with multiple projects, and websites, and I want to build and publish only a specific website and it's dependencies, how could it be done when using DevOps Pipelines, so it does not build the whole solution, but only the required projects for that specific website.
If you want to only build a single project in your solution, you could use the MSBuild task in Azure Devops Pipelines and then point it to the project you want to build.
Another way would be to in your VS solution to edit the Configuration Properties. In the Configuration Manager you can create a Configuration called Single_Project or something like that and then in the properties select which projects to build when using that configuration. Then when you use the VS Build task and specify the configuration you created for your build.

How to build F# projects with Azure Devops Pipelines? I get error 'The target "Build" does not exist in the project'

I'm tinkering with AzureDevops for the first time, to set up some CI tasks.
I have a public repository (opensource) with a solution (.sln) that has 3 F# projects. The solution builds fine in Windows/Mac/Linux.
However, if I try to set up a build pipeline with Azure Devops Pipelines, I get the error:
src\GWallet.Backend\GWallet.Backend.fsproj(0,0): Error MSB4057: The
target "Build" does not exist in the project.
Logs here.
My suspicion is that the build agent that is assigned to execute this doesn't have the F# tooling installed. Because I guess that the target "Build" is defined in the well-known Microsoft.FSharp.Targets file.
How to configure the Windows(VS2017) build agent to install the F# tooling so that this file is discoverable?
#nosami suggested a workaround, which I'm not very happy about (i.e.: I still think AzureDevops team should fix their default hosted agent to include F# tooling), but does the job: use the Microsoft.FSharp.Targets file provided by the nuget package called FSharp.Compiler.Tools. This is the diff in my opensource project if you're curious.
UPDATE: In case the above doesn't help or looks too intricated for you, I think one of this two answers could work: adjusting MSBuild properties of your project or using the proper version of MSBuild could work as well and is simpler.

What is the difference between octo.exe's create-release and octopack as an argument to msbuild

I am having trouble understanding the fundamentals of octopus deployment. I am using octo.exe with the create-release and deploy-release commands. I am also using the octopack plugin.
I am getting an error but that's not really the point - I want to understand how these peices fit together. I have searched and searched on this topic but every article seems to assume the reader has a ton of background info on octopus and automated deployment already, which I do not.
My question is: what is the difference between using octopack by passing the octopack argument to msbuild and simply creating a release using octo.exe? Do I need to do both, or will one or the other suffice? If both are needed, what do each of them do exactly?
Release and deployment as defined in the Octopus Deploy Documentation:
...a project is like a recipe that describes the steps (instructions) and variables (ingredients) required to deploy your apps and services. A release captures all the project and package details so it be deployed over and over in a safe and repeatable way. A deployment is the execution of the steps to deploy a release to an environment.
OctoPack is
...the easiest way to package .NET applications from your continuous integration/automated build process is to use OctoPack.
It is easy to use, but as Alex already mentioned, you could also use nuget.exe to create the package.
Octo.exe
is a command line tool that builds on top of the Octopus Deploy REST API.
It allows you to do much of the things you'd normally do through the Octopus Deploy web interface.
So, OctoPack and octo.exe serve a different purpose. You can't create a release with OctoPack and octo.exe is not for creating packages.
Octopack is there to NuGet package the project. It has some additional properties to help with pushing a package onto the NuGet feed, etc.
octo.exe is used to automate the creation of releases on the Octopus server and optionally deploy.
Note: a release in Octopus is basically a set of instructions on how to make the deployment. It includes the snapshot of variables and steps, references to the versions of the NuGet packages, etc.
octopack is a good starter, however I stopped using it some time ago with a few reasons.
No support for .Net 2.0 projects (and I needed to move all legacy apps into Octopus)
didn't like it modifying the project files (personal preference)
Pure nuget.exe was not much more work for me.

Build and Deploy a Web Application with TFS 2015 Build

We have just installed TFS 2015 (Update 1) on-premise and are trying to create a Continuous Integration/Build system using the new TFS Build system. The build works fine, and gives me a green light, but when I look at the default build it has only built the binaries from the bin directory, and there seems to be no easy way to deploy the app on-premise to a local server.
There are two deploy options for a filesystem copy, and a powershell script, and it would certainly be easy enough to use them to copy files to a new server, but since the build only built the binaries, I don't see a tool to gather up the Web artifacts (cshtml, images, scripts, css, etc..) for this.
After an exhaustive google search, I've only found one article which talks about this at:
http://www.deliveron.com/blog/building-websites-team-foundation-build-2015/
However, this uses WebDeploy and creates a rather messy deploy package.
How can I deploy the site (standard MVC web application, in fact my tests are using the default boilerplate site created by the create project wizard) complete with artifacts to a local server in the easiest possible way? I don't want to have to install WebDeploy on the servers, and would rather use PowerShell or something to deploy the final artifacts.
The build is just the standard Visual Studio build template, with 4 steps (Build, Test, Index & Publish, Publish Build Artifacts).
We use "Visual Studio Build" step and as Arguments for MSBuild we use following line:
/p:DeployOnBuild=True /p:PublishProfile=$(DeploymentConfiguration)
On Variables tab page DeploymentConfiguration has to be configured. It must be the Name of the publish Profile (filename of the pubxml file). If the file Name is Build.pubxml the publish profile is Build.
for example:
/p:DeployOnBuild=True /p:PublishProfile=Build
I wanted to add that Ben Day has an excellent write-up that helped us package quickly and then release to multiple environments through Release Manager.
His msbuild arguments look like this:
/p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=$(build.artifactstagingdirectory)\for-deploy\website
The difference between this and the accepted answer is that this parameter set stages everything in an artifacts folder, and then saves it as part of the build. We can then deploy exactly the same code repeatedly.
We capture the web.env.config files alongside the for-deploy folder and then use xdt transforms in the release process to ensure everything gets updated for whichever environment we're deploying to. It works well for all our web projects.
We use WebDeploy/MSDeploy for 40+ applications and love it. We do install WebDeploy on all our servers so we can deploy more easily but you could also use the Web Deploy On Demand feature which doesn't require WebDeploy be pre-installed.

TFS 2008/2010 vs Jenkins for Continuous Integration

Does anyone have specific experiences with using TFS 2008/2010 AND Jenkins for Continuous Integration (CI)? We are trying to decide which CI server to use. Our team works exclusively in Microsoft .NET/Visual Studio 2010/C#. We have the following requirements:
Automatically build our web project on every checkin.
Run unit tests with each build.
Automatically deploy green builds to development and/or test environments.
Provide pretty reports.
Provide build/deployment notifications via email.
I realize that installing a tool won't necessarily give us this functionality out-of-the-box and that we will have to integrate with other tools like MSBuild to achieve this.
I'm looking for specific features that Jenkins has that TFS 2008/2010 does not or vice versa. Also which is easier to maintain, use, etc.
I would highly recommend using Jenkins - it will do all of your requirements out of the box apart from possibly #3, but if you can script your deployments then it can do that as well.
Here are some links to help you get your builds up and running:
Blog about doing .NET builds in Jenkins
Jenkins Windows installers
Installing the Jenkins master and slaves as Windows services
Disclaimer: I have no experience with TFS, but I think open solutions are nearly always more flexible and extensible (and cheaper !) than proprietary products.
Late to this game, but I have used both TFS 2010 and Jenkins for CI. TFS 2010 has minimum set of CI tools in it. However, when you want to create a CI pipeline, it's a completely different story while Jenkins can easily create the pipeline.
If you are looking at only CI for one build either one should work. However, when it comes to the entire pipeline, Jenkins is way to go. With TFS it can be done, but Jenkins is better choice.
Here's quick bullet points:
TFS:
With a build definition you can compile, execute tests, return changeset/workitems, send an email when a build is broken
natural integration with visual studio
extremely hard to create CI pipeline. Requires custom handler and extensive workflow work. Not as intuitive as creating a build definition.
Because of the 3rd bullet, it's not easy to maintain/customize/scale CI pipeline
Jenkins:
Need to create a msbuild config file for CI, which is not much pain comparing to creating CI pipeline using TFS. However, TFS gives better/easier tool to create a build definition. however, it is not bad creating config file for msbuild for a project.
Creating a CI pipeline is very easy. Just chain them using upstream/downstream jenkins job trigger and passing an artifact from previous job.
Since Jenkins is very flexible, it is easy to create a jenkins plugin to meet your own needs and provide it to opensource community :)
In summary, if you need complete automated build, test, and deployment system go with Jenkins. If you just need only build and test, TFS might give you an edge over Jenkins.
If you're using Team 2010-2012, there is no reason whatsoever to bring in Jenkins. Team has all the features you listed, and the build process is ridiculously flexible.
Note that if you are stuck on Team 2008 or earlier, you should seriously look at Jenkins -- 2008 and earlier are quite primitive and inflexible compared to 2010 or later.

Resources