Totally automated Team Foundation 2017 build agent setup

First of all set the default TLS Version for .net to 1.2: With Chocolatey a lot of things are easy to set up:Visual Studio 2017 CommunityWindows Installer XML ToolsetVisual Studio CodeGitVersionNodeJsPython2Remote Server Administration ToolsNow let's modify visual studio and add some components, so that the node-gyp can compile popular packages. We could have used the windows build tools but they default to VS 2015 and the install location of python cannot be adjusted. Visual Studio C++ core features Microsoft.VisualStudio.Component.VC.CoreIdeWindows Universal C RuntimeMicrosoft.VisualStudio.Component.Windows10SDKWindows 10 SDK (10.0.16299.0) for Desktop C++ [x86 and x64]Microsoft.VisualStudio.Component.Windows10SDK.16299.DesktopVC++ 2017 v141 toolset (x86,x64)Microsoft.VisualStudio.Component.VC.Tools.x86.x64We will also utilize code generation using T4:Text Template TransformationMicrosoft.VisualStudio.Component.TextTemplatingThe new MsBuild Project  SDKs requires the installation of .NET Core components of Visual Studio. Otherwise you’ll receive errors like “Error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.”. Additionally we will add the .NET Framework targeting packs to build against several frameworks:.NET Core runtimeMicrosoft.Component.NetFX.Core.RuntimeMicrosoft.Net.Core.Component.SDK.NET Core 2.0 development toolsMicrosoft.NetCore.ComponentGroup.DevelopmentTools.NET Core 2.0 development toolsThe next issues arise: Visual Studio installer is lacking the –wait argument on the command line. So we need to start it as a new process and wait: Next update Visual Studio to its latest version: For Windows Installer XML Toolset we also want the Wix Toolset Visual Studio 2017 Extension to be installed. So we download the latest version from the Visual Studio Marketplace and install it silently: For python we need to add the install location to the path variable:Using NPM we nee to install the following packages globally:Node.js native addon build toolNode SassGulp And finally all together - the final script: HTH

Swallow GIT output in PowerShell run by Team Foundation Server because it’s STDERR which breaks the build

Imagine you want to commit and push a changed file during a build. Grant the user “Project Collection Build Service (DefaultCollection)” the following permissions on the repository:ContributeReadEnable the option “Allow scripts to access OAuth token” on the build.Set the variable “system.prefergit” to “true” on the build.Add a PowerShell-task to the buildRun… The issue is that either a) GIT has no idea what STDERR is and writes success messages to the error streamorb) TFS Build interprets the output of GIT wrong and fails the build even if the exit code is 0. Fun fact: It works with the “Command Line”-Task without any issues.Both out of my control – maybe another Issue/PR on the GIT project could solve it as it is open source, But I need a solution NOW! So here is how to modify the script: HTH

Builds with conditional NuGet publishing in Team Foundation Server

For a nightly build it makes no sense to publish a NuGet package as no code changed and therefore the same GitVersion is calculated.Since version 2017 Update 3 the on premise version of Microsoft's Team Foundation Server supports "Custom Conditions" on "Build Tasks" – but sadly not on "Task Groups".Here is what you need to exclude a step from a scheduled build: Here a screenshot of the condition in action:HTH

Using the Windows Credential Manager from MsBuild

Today I needed to make a web service call with authentication from MsBuild. Of course storing the credentials in plain text is not an option.The Windows Credential Manager User Interface can be opened by running the command:control /name Microsoft.CredentialManagerThere is also a command line interface:cmdkey.exeAs the Windows APIs are not provided as wrapper through the BCL a NuGet package comes to help:nuget.exe install CredentialManagementFinally everything wrapped up in a MsBuild Task:

Make a WebApplication project automatically publish on build

If you want to publish a Web Application project you can call MsBuild with parameters. Having a publish happen on each and every build - there is work to do. Visual Studio project files are MsBuild files since Version 2005. There is a way to force MsBuild and Visual Studio behave as requested. The project file needs to be edited slightly: <PropertyGroup> <PublishDestination>..\..\..\out\YourPublishDirectory</PublishDestination> </PropertyGroup> <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder" AfterTargets="Build"> <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" /> <ItemGroup> <PublishFiles Include="$(_PackageTempDir)\**\*.*" /> </ItemGroup> <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" /> </Target>

Updating the .NET target framework for many projects

I do component based development. Meaning I have 30+ repos, builds and each of them has 1-10 projects – The main library project, tests, samples and so on. The news about the support end for the .NET Framework 4, 4.5 and 4.5.1 was the motivation to update ALL of my projects. I know this is not neccessary because… .NET 4.5.2, 4.6 and 4.6.1 are compatible, in-place updates on top of .NET 4, .NET 4.5, and .NET 4.5.1. This means that applications built to target any of these previous .NET 4.x versions will continue running on .NET 4.5.2 without change. No recompiling of apps is necessary. ... but I wanted to update them from version 4 to since a long time now. To do the job I wrote a small powershell script. Beside the path command set-frameworkVersion there is CommitAndPush-GitRepositories which commits and pushes all repositories found underneath the path variable.

.NET Framework 4.6 Release

The new framework version is out. As with every new release it seems to me that the search indexes on Microsoft downloads have not been rebuilt yet. So I abuse this blog post and note the download links to myself…Microsoft .NET Framework 4.6 (Offline Installer) for Windows Vista SP2, Windows 7 SP1, Windows 8, Windows 8.1, Windows Server 2008 SP2 Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2 Microsoft Build Tools 2015Windows 10 and .NET Framework 4.6 SDKIntelliTrace Collector for Visual Studio 2015 (Just replace the Version number in the Installation Path)