Skip to content

Instantly share code, notes, and snippets.

@thoemmi
thoemmi / build.xml
Created May 11, 2011 09:07
Determine number of git revisions with inline MSBuild task
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="GitVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<LocalPath ParameterType="System.String" />
<Path ParameterType="System.String" />
<CommitCount ParameterType="System.Int32" Output="true" />
</ParameterGroup>
<Task>
using System;
using System.Diagnostics;
using System.Net;
namespace ConsoleApplication1 {
internal class Program {
private const int COUNT = 20;
private static void Main() {
var urls = new[] {
@thoemmi
thoemmi / SingleThreadedTaskScheduler.cs
Created February 9, 2012 16:31
SingleThreadedTaskScheduler
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace SingleThreadedTaskSchedulerDemo {
public class SingleThreadedTaskScheduler : TaskScheduler, IDisposable {
private readonly string _backgroundThreadName;
private readonly object _backgroundThreadLock = new object();
@thoemmi
thoemmi / Get-NuGetPackageFolder.ps1
Created May 4, 2012 20:18
Get-NuGetPackageFolder
function Get-NuGetPackageFolder {
param(
[string] $package_name,
[string] $nuget_packages_config
)
$xml = [xml](gc $nuget_packages_config)
$package = $xml.packages.package | where { $_.id -eq $package_name }
Join-Path $packages_dir ($package_name + "." + $package.version)
}
@thoemmi
thoemmi / psake.ps1
Created May 4, 2012 21:01
my psake file with getting latest psake from nuget
# Helper script for those who want to run psake without importing the module.
# Example:
# .\psake.ps1 "default.ps1" "BuildHelloWord" "4.0"
# Must match parameter definitions for psake.psm1/invoke-psake
# otherwise named parameter binding fails
param(
[Parameter(Position=0,Mandatory=0)]
[string]$buildFile = 'default.ps1',
[Parameter(Position=1,Mandatory=0)]
@thoemmi
thoemmi / Expand-ZipFile.ps1
Created May 6, 2012 17:18
Expand-ZipFile
function Expand-ZipFile {
param {
$zipPath,
$destination,
[switch] $quiet
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipPath)
$destinationFolder = $shellApplication.NameSpace($destination)
@thoemmi
thoemmi / Add-XmlFragment.ps1
Created June 15, 2012 15:50
PowerShell function to add an XML fragment to an XmlNode
<#
.SYNOPSIS
Adds an XML fragment to an XmlNode
.DESCRIPTION
Adds an XML fragment to an XmlNode
.NOTES
Author : Thomas Freudenberg - info@thomasfreudenberg.com
@thoemmi
thoemmi / PreBuild.targets.xml
Created August 26, 2012 21:22
a msbuild target file creating a CommonAssemblyInfo.cs based on `git describe`
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
TaskName="GetVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<VersionString ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Output="true" />
@thoemmi
thoemmi / Microsoft.PowerShell_profile.ps1
Created September 14, 2012 08:21
my PowerShell profile script
# red background if running elevated
& {
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
if ($IsAdmin)
{
(get-host).UI.RawUI.Backgroundcolor="DarkRed"
clear-host
@thoemmi
thoemmi / PreBuild.targets.xml
Created September 14, 2012 19:58
Embed referenced assemblies, because ILMerge won't work with WPF applications
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Originally written by Daniel Chambers (http://www.digitallycreated.net)
http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application
-->
<Target Name="EmbedReferencedAssemblies" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<!-- get list of assemblies marked as CopyToLocal -->
<AssembliesToEmbed Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' == '.dll'"/>