PowerShell Snippet#5: Running MSBuild

Script on running MSBuild via PowerShell. This ties up neatly with my previous post.


$msbuild = "C:\Windows\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe"
$MsBuilExists = Test-Path $msbuild
If ($MsBuilExists -ne $true) {write-host "msbuild does not exist at this location. Install Visual Studio 2015 (Community Edition should be adequate)"}
$buildFile = $PSScriptRoot+"\BuildAllDBProjects.targets.xml"
& $msbuild $buildFile

MSBuild Snippet#1 : Ignore Solutions

How do we ignore solutions in a build? We could specify only the ones we want to build, but depending on your weighting of include/exclude solutions, this could be costly. So here’s how to ignore solutions using MSBuild:

 


<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Default">

<ItemGroup>
<ProjectReference Include=".\**\AV2014.sln" Exclude=".\**\DBSolutionToIgnore.sln"/>
</ItemGroup>

<Target Name="Default">
<MSBuild Projects="@(ProjectReference)" Targets="Rebuild"/>
</Target>

</Project>

SSISMSBuild Updated and Moved

New! (Sorta) Improved! (Kinda)

In a long running series of loosely related posts, I have updated the SSISMSBuild Project that I uploaded to CodePlex some years ago.

But wait, there’s more!

The updates are just references and updating the .net target framework to keep it current, however I also have moved it from CodePlex to GitHub. Mainly because I’ve started uploading other projects there so I want to keep my git skills fresh because I tend to forget stuff twice as quickly as I learn them!

References!

Once you download the solution, you may find that the references to a few of the dlls are broken. This is a common problem with these dlls, and the solution is to unload the project and edit the references. Chances are the dlls will be in this location. C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio

You will need client tools installed as part of your SQL Server installation or the dlls won’t be on your box. Either way just search for those dll names in “C:\Program Files (x86)\Microsoft SQL Server\” and they will probably be found.

 

How To Compile SQLProj Files Using Cmdline MSBuild… Errors Included!

I’m fully back into builds and Visual Studio and even unit testing using MSTest once again, and I’m enjoying it very much. But I’m still working with databases, though less in a DBA-capacity. I recently needed to build and deploy about 40 small database projects that were in 4 or 5 different database solutions. And I needed to do this several times a day, so compiling via Visual Studio would be a boring and tedious process. So to speed up the process I decided to write the build process in an MSBuild target file and call initiate the build process through PowerShell. The targets file was simple enough to put together.


<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Default">

<ItemGroup>
<ProjectReference Include=".\**\*.sln" Exclude=".\**\DBSolutionToIgnore.sln"/>
</ItemGroup>

<Target Name="Default">
<MSBuild Projects="@(ProjectReference)" Targets="Rebuild"/>
</Target>

</Project>

Continue reading “How To Compile SQLProj Files Using Cmdline MSBuild… Errors Included!”

Running Clean Builds On Visual Studio Team Services

Hello!

Recently I have been using Visual Studio Team System for builds and unit testing. I’ve actually really enjoyed getting back to working with builds and testing again, and I’m amazed at just how different it is running builds on VSTS instead of on-premises TFS build servers. Whereas I was used to use massive MSbuild files with tasks etc, or those awful Workflow builds that I never really adopted[1], the build process online is ridiculously straightforward, and the hosted build process machines have pretty much every piece of software you could hope to have running on a build server. Continue reading “Running Clean Builds On Visual Studio Team Services”

SSIS 2012 Deployment Fail Revisited

( Part 2 focuses on clearing out the SSISDB by creating new stored proc based on the one used by the maintenance job. If your Maintenance Job is taking hours to run, you need to check this out.)

When deploying our Ispacs through my builds, I’ve still been getting the intermittent “timeout” issues I first wrote about back in May, and this has been exacerbated by extra SSIS Projects added to the SSISDB catalog.

Continue reading “SSIS 2012 Deployment Fail Revisited”

Associating changesets and Work Items Since the Last Successful Build

Way back in 2008, a post on the blogs.msdn site showed how to create a custom MSBuild task to associate changesets and work items only since the last successful build. Recently I needed to write this custom task myself, but for builds that were “PartiallySuccessful” as well as “Successful”, and was pleased to find such a complete target available. However as it is written for TFS 2008 it won’t work with TFS 2010 onwards. As the blog appears to be inactive now I’ve made the changes and put the code below. Hopefully anyone who needs it for TFS 2010 onwards can use the pingback to get here for the up to date code. The rest of the solution works fine.

Continue reading “Associating changesets and Work Items Since the Last Successful Build”

Who Got The Func Part 3: Generating a GUID in MSBuild

I’m in a bit of a Property Function mood at the moment with our builds. We generate a GUID within our builds for an Id required in one of our config file and some more for our WiX installers. There’s two ways to create GUIDs. Which one you use really depends on what version of MSBuild you are using.

Continue reading “Who Got The Func Part 3: Generating a GUID in MSBuild”

Who Got The Func Part 2: Property Functions in MSBuild

Not so long ago I posted about string manipulations in SQL. Seeing as I recently had to use the MSBuild property functions I thought it best to post a fairly advanced example of using the .Net property functions in MSBuild as most of the examples  I have found online are useful to no one. The kind of example I am talking about is found on the MSDN page:


$(ProjectOutputFolder.Substring(0,3))

It’s useful to know the syntax, but really not going to help me out in my scenario. Continue reading “Who Got The Func Part 2: Property Functions in MSBuild”

How to: Use the Same Target in Multiple Project Files

How to: Use the Same Target in Multiple Project Files.

Further to my post yesterday about Importing projects in MSBuild, it’s worth having a quick read over the “Order of Evaluation” section to understand further that it is important where you import a project if you wish to set the properties and items of the imported project.(TL;DR –

Continue reading “How to: Use the Same Target in Multiple Project Files”